Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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://site.com/json/airlines.json'), true), 'iata', 'name');
- $cit=json_decode(file_get_contents("http://site.com/json/cities.json")); $cities=array(); foreach($cit as $val) { if(property_exists($val->name_translations,"ru")) $cities[$val->code]=$val->name_translations->ru;}
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://api.travelpayouts.com/v2/prices/latest?currency=rub&period_type=year&page=1&limit=30&token=token&show_to_affiliates=true¤cy=rub&sorting=route");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_HEADER, FALSE);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Access-Token: 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;
- }
- ?>
- <table class="mytable">
- <thead style="background: rgba(2, 69, 141, 0.46) none repeat scroll 0% 0%; color: rgb(255, 255, 255);">
- <tr>
- <th class="views-field views-field-field-logo-fid">
- Кол-во </th>
- <th class="views-field views-field-tid">
- Класс </th>
- <th class="views-field views-field-tid-1">
- Вылет </th>
- <th class="views-field views-field-field-napravlenie-value">Прилёт
- </th>
- <th class="views-field views-field-field-cenaot-value">
- Дата В </th>
- <th class="views-field views-field-field-prodsgas-value">Обратно</th>
- <th class="views-field views-field-field-prodsgapo-value">
- Пересадок </th>
- <th class="views-field views-field-field-perelets-value">Цена руб.</th>
- <th class="views-field views-field-field-pereletpo-value">
- Дата поиска</th>
- <th class="views-field views-field-nothing">
- Расстояние (км.) </th><th class="views-field views-field-Actual">
- Актуально</th></tr>
- </thead>
- <?php if(isset($products['data']) && is_array($products['data'])){?>
- <?php foreach ($products['data'] as $key => $data) {?>
- <?php foreach ($data as $field=> $val) {?>
- <td><?php echo $replace_value($field, $val);?></td> <?}?>
- </tr>
- <?php }?> <?}?>
- </table>
- {"success":true,"data":{"AER":{"origin":"MOW","destination":"AER","price":3300,"transfers":0,"airline":"S7","flight_number":1021,"departure_at":"2016-03-12T23:30:00Z","return_at":"2016-03-16T16:40:00Z","expires_at":"2016-02-09T13:11:16Z"},"BCN":{"origin":"MOW","destination":"BCN","price":12749,"transfers":0,"airline":"U6","flight_number":7045,"departure_at":"2016-06-04T04:55:00Z","return_at":"2016-06-11T09:30:00Z","expires_at":"2016-02-09T14:21:23Z"},"BKK":{"origin":"MOW","destination":"BKK","price":27016,"transfers":1,"airline":"GF","flight_number":15,"departure_at":"2016-02-23T14:50:00Z","return_at":"2016-05-02T21:30:00Z","expires_at":"2016-02-09T12:43:02Z"},"HKT":{"origin":"MOW","destination":"HKT","price":32971,"transfers":1,"airline":"CA","flight_number":910,"departure_at":"2016-02-25T18:55:00Z","return_at":"2016-03-17T01:40:00Z","expires_at":"2016-02-07T09:28:18Z"},"KGD":{"origin":"MOW","destination":"KGD","price":3500,"transfers":0,"airline":"S7","flight_number":67,"departure_at":"2016-02-10T14:00:00Z","return_at":"2016-03-17T16:00:00Z","expires_at":"2016-02-07T20:42:05Z"},"KRR":{"origin":"MOW","destination":"KRR","price":3465,"transfers":0,"airline":"DP","flight_number":157,"departure_at":"2016-03-01T19:05:00Z","return_at":"2016-03-07T13:35:00Z","expires_at":"2016-02-09T13:13:08Z"},"LED":{"origin":"MOW","destination":"LED","price":2789,"transfers":0,"airline":"U6","flight_number":91,"departure_at":"2016-03-15T11:50:00Z","return_at":"2016-03-16T16:00:00Z","expires_at":"2016-02-06T21:40:46Z"},"MRV":{"origin":"MOW","destination":"MRV","price":3271,"transfers":0,"airline":"S7","flight_number":1215,"departure_at":"2016-03-17T16:40:00Z","return_at":"2016-03-23T19:55:00Z","expires_at":"2016-02-06T18:57:52Z"},"SIP":{"origin":"MOW","destination":"SIP","price":3965,"transfers":0,"airline":"WZ","flight_number":301,"departure_at":"2016-02-21T17:30:00Z","return_at":"2016-02-25T12:30:00Z","expires_at":"2016-02-09T12:21:59Z"},"TBS":{"origin":"MOW","destination":"TBS","price":8071,"transfers":0,"airline":"S7","flight_number":955,"departure_at":"2016-03-08T12:50:00Z","return_at":"2016-03-11T17:25:00Z","expires_at":"2016-02-09T12:57:16Z"}},"error":null,"currency":"rub"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement