Answer the question
In order to leave comments, you need to log in
How to extract a specific value from Json?
Hello everyone, I'm back again, Happy New Year everyone, please tell me. There is a code
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.travelpayouts.com/v1/city-directions?origin=MOW&token=xxxxxxx&limit=10");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Access-Token: xxxxxx"));
$response = curl_exec($ch);
curl_close($ch);
$json=json_decode($response,true);
?>
<?php
$products=json_decode($response,true);
foreach ($products as $key => $value) {
echo "<table class='mytable'><hr>";
foreach ($value as $k=> $v) {
echo "<tr><td><br>".$k."</td><td></td></tr>";
foreach ($v as $g=> $l) {
$g=str_replace ('price','цена',$g);
$g=str_replace ('airline','авиакомпания',$g);
$g=str_replace ('origin','город вылета',$g);
$g=str_replace ('destination','город прилета',$g);
$g=str_replace ('transfers','кол-во пересадок',$g);
$g=str_replace ('flight_number','номер рейса',$g);
$g=str_replace ('departure_at','дата вылета',$g);
$g=str_replace ('return_at','дата возвращения',$g);
$g=str_replace ('expires_at','Срок истечения актуальности цены',$g);
echo "<tr><td>".$g."</td><td>".$l."</td></tr>";
}
}
echo "</table>";
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question