Guest User

Untitled

a guest
Dec 15th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. <?php
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, "http://api.travelpayouts.com/v1/prices/cheap?origin=ABA&destination=MOW&limit=1&token=91b5b4bed0355fa89cd2e1f783abf710");
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  5. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  6. curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Access-Token: 91b5b4bed0355fa89cd2e1f783abf710"));
  7. $response = curl_exec($ch);
  8. curl_close($ch);
  9. $products=json_decode($response,true);
  10. ?>
  11.  
  12. <?php if(isset($products['data']) && is_array($products['data'])) {
  13. foreach ($products['data'] as $key => $data) {
  14. echo ($data[0]['price']);
  15. foreach ($data as $destination => $row) {
  16. }
  17. }
  18. }
  19. ?>
  20.  
  21. <?php
  22. $ch = curl_init();
  23. curl_setopt($ch, CURLOPT_URL, "http://api.travelpayouts.com/v1/prices/cheap?origin=ABA&destination=AER&limit=1&token=91b5b4bed0355fa89cd2e1f783abf710");
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  25. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  26. curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Access-Token: 91b5b4bed0355fa89cd2e1f783abf710"));
  27. $response = curl_exec($ch);
  28. curl_close($ch);
  29. $products=json_decode($response,true);
  30. ?>
  31.  
  32. <?php if(isset($products['data']) && is_array($products['data'])) {
  33. foreach ($products['data'] as $key => $data) {
  34. echo ($data[0]['price']);
  35. foreach ($data as $destination => $row) {
  36. }
  37. }
  38. }
  39. ?>
  40.  
  41. <?php
  42. $ch = curl_init();
  43. curl_setopt($ch, CURLOPT_URL, "http://api.travelpayouts.com/v1/prices/cheap?origin=ABA&destination=HKT&limit=1&token=91b5b4bed0355fa89cd2e1f783abf710");
  44. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  45. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  46. curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Access-Token: 91b5b4bed0355fa89cd2e1f783abf710"));
  47. $response = curl_exec($ch);
  48. curl_close($ch);
  49. $products=json_decode($response,true);
  50. ?>
  51.  
  52. <?php if(isset($products['data']) && is_array($products['data'])) {
  53. foreach ($products['data'] as $key => $data) {
  54. echo ($data[0]['price']);
  55. foreach ($data as $destination => $row) {
  56. }
  57. }
  58. }
  59. ?>
  60.  
  61. array(2) {
  62. [1]=>
  63. array(6) {
  64. ["price"]=>
  65. int(20400)
  66. ["airline"]=>
  67. string(2) "S7"
  68. ["flight_number"]=>
  69. int(3034)
  70. ["departure_at"]=>
  71. string(20) "2018-01-28T09:10:00Z"
  72. ["return_at"]=>
  73. string(20) "2018-02-03T16:20:00Z"
  74. ["expires_at"]=>
  75. string(20) "2017-12-17T05:55:26Z"
  76. }
  77. [2]=>
  78. array(6) {
  79. ["price"]=>
  80. int(25200)
  81. ["airline"]=>
  82. string(2) "S7"
  83. ["flight_number"]=>
  84. int(3034)
  85. ["departure_at"]=>
  86. string(20) "2018-01-28T09:10:00Z"
  87. ["return_at"]=>
  88. string(20) "2018-02-03T05:20:00Z"
  89. ["expires_at"]=>
  90. string(20) "2017-12-17T05:55:26Z"
  91. }
  92. }
  93.  
  94. foreach ($products['data'] as $destination => $data) {
  95. foreach ($data as $dataKey => $dataValue) {
  96. echo $dataValue['price'].PHP_EOL;
  97. }
  98. }
  99.  
  100. foreach ($products['data'] as $destination => $data) {
  101. $iNeedOnlyThisValue = array_shift($data); //После этого в дате не будет одного значения
  102. echo $iNeedOnlyThisValue['price'].PHP_EOL;
  103. }
Add Comment
Please, Sign In to add comment