Использование остального хочет показать детали о деталях, но есть ошибка в функциональном коде, но, по моему мнению, это правильно, но есть ошибка в 7-й строке. У меня есть два кода они являются следующие index.phpс помощью отдыха показать детали
<?php
header("content-Type:application/json");
include("function.php");
if(!empty($_GET['name'])){
$name = $_GET['name'];
$price = get_price($name);
if(empty($price))
deliver_response(200,"book not found",NULL);
else
deliver_response(200,"book found",price);
}
else{
deliver_response(400,"invalid",NULL);
}
function deliver_response($status,$status_message,$data)
{
header("HTTP/1.1 $status $status_message");
$response['status']=$status;
$response['status_message']=$status_message;
$response['data']=$data;
$json_response=json_encode($response);
echo $json_response;
}
?>
функция кода
<?php
function get_price($find)
{
$books = array(
"java" => 300,
"c" => 250,
"php" => 350);
for($books as $book => $price) {
if($books == $find) {
return $price;
break;
}
}
}
?>