How to make data not repeated?

There is a code
<code><?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('http://aviaciya.com/json/airlines.json'), true), 'iata', 'name');
$cit=json_decode(file_get_contents("http://aviaciya.com/json/cities.json")); $cities=array(); foreach($cit as $val) { if(property_exists($val--->name_translations,"EN")) $cities[$val->code]=$val->name_translations->EN;}


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.travelpayouts.com/v1/city-directions?origin=MOW¤cy=RUB&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)) {
?>
<div class="cont">
 <h3 class="title"><?= $replace_value('destination',$key) ? $replace_value('destination', $key) : "<b>" .'Update.'. ""; ?></h3>
 <div class="content">
 <a rel="nofollow" alt="tickets Moscow <?php echo $replace_value('destination',$key); ?>" title="tickets Moscow <?php echo $replace_value('destination',$key); ?>" href="http://bilety.avia-avia.ru/searches/new?origin_iata=MOW&destination_iata=<?=$key?>&depart_date=<?=substr($row['departure_at'], 0, 10)?>&return_date=<?=substr($row['return_at'], 0, 10)?>&adults=1&children=0&infants=0&trip_class=0&marker=87111&with_request=true">
 <div class="content-overlay"></div>
 <img class="content-image" src="//photo2.hotellook.com/static/cities/320x240/<?= $key ?>.jpg">
 <div class="content-details fadeIn-bottom">
 <h3 class="content-title">Price</h3>
 <p class="content-text"><?= $data['price'] ?> RUB.</p>
</div>
</a>
</div>
</div>


<?php
}
}
}
}
?></code>

Is the answer
{"success":true,"data":{"AER":{"origin":"MOW","destination":"AER","price":3365,"transfers":0,"airline":"WZ","flight_number":121,"departure_at":"2016-12-19T08:35:00Z","return_at":"2016-12-30T03:30:00Z","expires_at":"2016-12-02T11:20:08Z"},"BKK":{"origin":"MOW","destination":"BKK","price":15860,"transfers":1,"airline":"QR","flight_number":234,"departure_at":"2017-02-18T12:55:00Z","return_at":"0001-01-01T00:00:00Z","expires_at":"2016-12-01T20:42:46Z"},"EVN":{"origin":"MOW","destination":"EVN","price":7359,"transfers":0,"airline":"UT","flight_number":879,"departure_at":"2016-12-04T02:30:00Z","return_at":"2017-01-01T12:45:00Z","expires_at":"2016-11-30T21:02:17Z"},"HKT":{"origin":"MOW","destination":"HKT","price":14409,"transfers":1,"airline":"QR","flight_number":230,"departure_at":"2016-11-30T23:50:00Z","return_at":"0001-01-01T00:00:00Z","expires_at":"2016-11-30T23:50:00Z"},"KRR":{"origin":"MOW","destination":"KRR","price":3663,"transfers":0,"airline":"R3","flight_number":726,"departure_at":"2017-04-08T11:40:00Z","return_at":"2017-04-11T22:05:00Z","expires_at":"2016-12-02T20:57:33Z"},"LED":{"origin":"MOW","destination":"LED","price":2687,"transfers":0,"airline":"N4","flight_number":167,"departure_at":"2016-12-02T07:05:00Z","return_at":"2016-12-05T22:30:00Z","expires_at":"2016-12-02T07:05:00Z"},"MCX":{"origin":"MOW","destination":"MCX","price":3516,"transfers":0,"airline":"DP","flight_number":187,"departure_at":"2017-01-16T07:40:00Z","return_at":"2017-01-20T21:50:00Z","expires_at":"2016-12-01T13:26:27Z"},"MRV":{"origin":"MOW","destination":"MRV","price":3585,"transfers":0,"airline":"U6","flight_number":153,"departure_at":"2016-12-16T12:25:00Z","return_at":"2016-12-16T18:00:00Z","expires_at":"2016-12-02T16:39:50Z"},"PRG":{"origin":"MOW","destination":"PRG","price":7664,"transfers":1,"airline":"JU","flight_number":651,"departure_at":"2017-02-20T11:50:00Z","return_at":"2017-03-06T20:35:00Z","expires_at":"2016-12-02T15:29:34Z"},"SIP":{"origin":"MOW","destination":"SIP","price":4054,"transfers":0,"airline":"N4","flight_number":123,"departure_at":"2017-02-09T07:45:00Z","return_at":"2017-02-13T11:10:00Z","expires_at":"2016-12-02T19:48:06Z"}},"error":null,"currency":"RUB"}


Here's what happens: avia-avia.ru/test2 Data is duplicated how to remove the duplicate, thanks in advance. It seems that the loop goes 9 times.
July 2nd 19 at 13:06
0 answer

Find more questions by tags PHPJSON