Есть Json запрос
<?php
$map = function($array, $from, $to){
$result = [];
if(!empty($array) && is_array($array)){
foreach ($array as $element) {
$key = $element[$from]?:null;
$value = $element[$to]?:null;
if($key && $value){
$result[$key] = $value;
}
}
}
return $result;
};
$airlines = $map(json_decode(file_get_contents('/json/airlines.json'), true), 'iata', 'name');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.travelpayouts.com/v1/prices/cheap?origin=MOW&destination=AER&limit=1&token=*********");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Access-Token: *********"));
$response = curl_exec($ch);
curl_close($ch);
$products=json_decode($response,true);
$replace_value = function($key, $val) use ($cities, $airlines){
$response = $val;
switch($key){case 'destination':
$response = $cities[$val];break;
case 'origin':
$response = $cities[$val];break;
case 'airline':
$response = $airlines[$val];
break;
}
return $response;
}
?>
<?php
if(isset($products['data']) && is_array($products['data'])) {
foreach ($products['data'] as $key => $data) {
foreach ($data as $destination => $row) {
if (preg_match('/[A-Z]{3}/i', $key)) {
?>
Есть ответ Json
{"success": true, "data": {"AER":{"0":{"price":3455,"airline":"WZ","flight_number":121,"departure_at":"2016-12-19T08:35:00Z","return_at":"2016-12-30T03:30:00Z","expires_at":"2016-11-26T12:06:18Z"},"1":{"price":5946,"airline":"NN","flight_number":349,"departure_at":"2017-02-18T15:45:00Z","return_at":"2017-02-20T12:15:00Z","expires_at":"2016-11-26T06:47:00Z"},"2":{"price":7897,"airline":"UT","flight_number":489,"departure_at":"2017-02-18T21:00:00Z","return_at":"2017-03-10T06:00:00Z","expires_at":"2016-11-26T10:54:50Z"}}}}
Мне нужно вывести только первый Price, я это делаю вот так
<?php echo $row['price'][0]; ?> RUB <?php
}
}
}
}
?>
Но выводятся все равно все Price. Как решить задачу? заранее спасибо за ответ, с уважением.