phpの参考書で勉強中です。
windows10、XAMPP for windows 7.3.12を使っています。
以下のphpのプログラムを実行するとrequireでエラーになります。
エラーでは'restaurant-functions.php'が開けないか、ファイルがないと
でています。コードをチェックしましたが、どこも悪くないようなのですが、解決できないので教えてくださいお願い致します。
php
1<?php 2 // 別ファイルの参照 3 require 'restaurant-functions.php'; 4 // 25ドルの請求に加え8.25%の税金と20%のチップ 5 $total_bill = restuarant_check(25,8.875,20); 6 7 // 手持ちは30ドル 8 $cash = 30; 9 10 print "I need to pay with ".payment_method($cash,$total_bill);コード
PHP
1// 返り値の型の宣言 2 function restaurant_check($meal,$tax,$tip){ 3 $tax_amount = $meal*($tax/100); 4 5 $tip_amount = $meal*($tip/100); 6 7 $total_amount = $meal + $tax_amount + $tip_amount ; 8 9 return $total_amount; 10 } 11
PHP
1// 複数のreturn文を持つ関数 2 function payment_method($cash_on_hand,$amount){ 3 4 if($amount > $cash_on_hand){ 5 6 return 'credit_card'; 7 8 }else{ 9 return 'cash'; 10 } 11 } 12
error
1Fatal error: Uncaught Error: Call to undefined function restuarant_check() in C:\xampp\htdocs\php_oreilly\chap5\5-27.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\php_oreilly\chap5\5-27.php on line 5 2 3//paiza.io 4//実行エラー 5 6PHP Warning: require(restaurant-functions.php): failed to open stream: No such file or directory in /workspace/Main.php on line 4 7PHP Fatal error: require(): Failed opening required 'restaurant-functions.php' (include_path='.:/usr/share/php') in /workspace/Main.php on line 4 8 9
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/02/01 15:02
退会済みユーザー
2020/02/01 15:05