Задать вопрос

Как сделать вывод первой и последней строки в JSON через PHP?

Привет всем! Ребята помогите реализовать вывод, не получается сделать вывод (получается выводить циклом только, но всех начений из stops через json_decode)! Нужно сделать вывод именно двух строк из json на php
тоесть вывод значения только что в этих строках

stops->0->station->code
stops->11->station->code

на выходе должно получится

s9734072
s9771828

Код json
{"except_days":"","arrival_date":null,"from":null,"uid":"empty_3_f9734072t9771828_86","title":"Жлобин — Отрубы","departure_date":null,"start_time":"05:00","number":"","short_title":"Жлобин — Отрубы","days":"пн","to":null,"carrier":null,"transport_type":"bus","stops":[{"arrival":null,"departure":"2018-09-24 05:00:00","terminal":null,"platform":"","station":{"code":"s9734072","station_type":"bus_station","title":"Жлобин","popular_title":"","short_title":"","codes":{"yandex":"s9734072"},"transport_type":"bus","station_type_name":"автовокзал","type":"station"},"stop_time":null,"duration":0.0},{"arrival":"2018-09-24 05:11:00","departure":"2018-09-24 05:12:00","terminal":null,"platform":"","station":{"code":"s9771537","station_type":"bus_stop","title":"Малые Роги","popular_title":null,"short_title":null,"codes":{"yandex":"s9771537"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":720.0},{"arrival":"2018-09-24 05:13:00","departure":"2018-09-24 05:14:00","terminal":null,"platform":"","station":{"code":"s9771538","station_type":"bus_stop","title":"Солоное","popular_title":null,"short_title":null,"codes":{"yandex":"s9771538"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":840.0},{"arrival":"2018-09-24 05:19:00","departure":"2018-09-24 05:20:00","terminal":null,"platform":"","station":{"code":"s9771539","station_type":"bus_stop","title":"Грабск","popular_title":null,"short_title":null,"codes":{"yandex":"s9771539"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":1200.0},{"arrival":"2018-09-24 05:27:00","departure":"2018-09-24 05:28:00","terminal":null,"platform":"","station":{"code":"s9771542","station_type":"bus_stop","title":"Папоротное","popular_title":null,"short_title":null,"codes":{"yandex":"s9771542"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":1680.0},{"arrival":"2018-09-24 05:33:00","departure":"2018-09-24 05:34:00","terminal":null,"platform":"","station":{"code":"s9771673","station_type":"bus_stop","title":"Возрождение","popular_title":null,"short_title":null,"codes":{"yandex":"s9771673"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":2040.0},{"arrival":"2018-09-24 05:37:00","departure":"2018-09-24 05:38:00","terminal":null,"platform":"","station":{"code":"s9771674","station_type":"bus_stop","title":"Гелин","popular_title":null,"short_title":null,"codes":{"yandex":"s9771674"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":2280.0},{"arrival":"2018-09-24 05:43:00","departure":"2018-09-24 05:44:00","terminal":null,"platform":"","station":{"code":"s9771675","station_type":"bus_stop","title":"Косаковка","popular_title":null,"short_title":null,"codes":{"yandex":"s9771675"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":2640.0},{"arrival":"2018-09-24 05:52:00","departure":"2018-09-24 05:53:00","terminal":null,"platform":"","station":{"code":"s9771676","station_type":"bus_stop","title":"Великий Лес","popular_title":"","short_title":"","codes":{"yandex":"s9771676"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":3180.0},{"arrival":"2018-09-24 06:03:00","departure":"2018-09-24 06:04:00","terminal":null,"platform":"","station":{"code":"s9771677","station_type":"bus_stop","title":"Кабановка","popular_title":null,"short_title":null,"codes":{"yandex":"s9771677"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":3840.0},{"arrival":"2018-09-24 06:11:00","departure":"2018-09-24 06:12:00","terminal":null,"platform":"","station":{"code":"s9771827","station_type":"bus_stop","title":"Ляды","popular_title":null,"short_title":null,"codes":{"yandex":"s9771827"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":60,"duration":4320.0},{"arrival":"2018-09-24 06:23:00","departure":null,"terminal":null,"platform":"","station":{"code":"s9771828","station_type":"bus_stop","title":"Отрубы","popular_title":null,"short_title":null,"codes":{"yandex":"s9771828"},"transport_type":"bus","station_type_name":"автобусная остановка","type":"station"},"stop_time":null,"duration":4980.0}],"vehicle":null,"start_date":"2018-09-24","transport_subtype":{"color":null,"code":null,"title":null},"express_type":null}



Заранее благодарен вам!
  • Вопрос задан
  • 163 просмотра
Подписаться 1 Средний Комментировать
Решения вопроса 1
DevMan
@DevMan
print_r($data->stops[0]);
print_r(end($data->stops));
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
mannaro
@mannaro
Умею профессионально гуглить
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы