0

Имеем многомерный массив

$return_data = json_decode($response);

как вывести к примеру Sun 7 Showers ? Что не пробую или не выводит или ошибка. Содержание массива

stdClass Object ( 
[location] => stdClass Object ( 
[woeid] => 924584 
[city] => Kryvyy Rih 
[region] => Dnipropetrovsk Oblast 
[country] => Ukraine 
[lat] => 47.9063 
[long] => 33.394699 
[timezone_id] => Europe/Kiev ) 

[current_observation] => stdClass Object ( 

[wind] => stdClass Object ( 
[chill] => 17 
[direction] => 35 
[speed] => 7 ) 

[atmosphere] => stdClass Object (
[humidity] => 51 
[visibility] => 16.1
[pressure] => 999 
[rising] => 0 ) 

[astronomy] => stdClass Object ( 
[sunrise] => 6:02 am 
[sunset] => 7:33 pm ) 

[condition] => stdClass Object ( 
[text] => Showers 
[code] => 11 
[temperature] => 17 ) 

[pubDate] => 1555070400 )




 [forecasts] => Array (

 [0] => stdClass Object (
     [day] => Fri 
     [date] => 1555016400
     [low] => 8 
     [high] => 17
     [text] => Showers 
     [code] => 11 ) 

 [1] => stdClass Object (
     [day] => Sat 
     [date] => 1555102800 
     [low] => 7 
     [high] => 17
     [text] => Showers 
     [code] => 11 ) 

 [2] => stdClass Object (
     [day] => Sun 
     [date] => 1555189200 
     [low] => 7
     [high] => 14 
     [text] => Showers 
     [code] => 11 ) 
  ) )  
2
  • $return_data = json_decode($response, true);
    – user212578
    13 апр 2019 в 12:35
  • Вы имеете не массив, а объект, для того. чтобы был массив, нужно вторым аргументом функции json_decode выставить флаг true, чтобы была конвертация из объекта в массив.
    – And
    13 апр 2019 в 12:38

1 ответ 1

2

Такой код:

 echo $return_data->forecasts[2]->day

Ну и т.д.

3
  • 2
    ->day только.
    – teran
    13 апр 2019 в 12:31
  • @teran да, там ведь тоже object 13 апр 2019 в 12:36
  • Огромная вам благодарность ))) 13 апр 2019 в 13:57

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.