php - What i do wrong with stdClass? -


var_dump($w);  object(stdclass)#691 (2) { ["name"]=> string(4) "riga" ["weather"]=> array(7) { [0]=> object(stdclass)#535 (9) { ["w_ico"]=> string(3) "10d" ["dt"]=> int(1470650400) ["temp_day"]=> int(23) ["temp_night"]=> int(19) ["temp_eve"]=> int(23) ["temp_morn"]=> int(23) ["wind_speed"]=> int(8) ["wind_deg"]=> int(231) ["humidity"]=> int(81) } [1]=> object(stdclass)#536 (9) { ["w_ico"]=> string(3) "02d" ["dt"]=> int(1470736800) ["temp_day"]=> int(19) ["temp_night"]=> int(17) ["temp_eve"]=> int(20) ["temp_morn"]=> int(18) ["wind_speed"]=> int(9) ["wind_deg"]=> int(236) ["humidity"]=> int(88) } [2]=> object(stdclass)#537 (9) { ["w_ico"]=> string(3) "10d" ["dt"]=> int(1470823200) ["temp_day"]=> int(18) ["temp_night"]=> int(16) ["temp_eve"]=> int(18) ["temp_morn"]=> int(16) ["wind_speed"]=> int(8) ["wind_deg"]=> int(218) ["humidity"]=> int(94) } [3]=> object(stdclass)#538 (9) { ["w_ico"]=> string(3) "10d" ["dt"]=> int(1470909600) ["temp_day"]=> int(18) ["temp_night"]=> int(15) ["temp_eve"]=> int(16) ["temp_morn"]=> int(16) ["wind_speed"]=> int(5) ["wind_deg"]=> int(207) ["humidity"]=> int(0) } [4]=> object(stdclass)#539 (9) { ["w_ico"]=> string(3) "10d" ["dt"]=> int(1470996000) ["temp_day"]=> int(18) ["temp_night"]=> int(12) ["temp_eve"]=> int(16) ["temp_morn"]=> int(15) ["wind_speed"]=> int(4) ["wind_deg"]=> int(283) ["humidity"]=> int(0) } [5]=> object(stdclass)#540 (9) { ["w_ico"]=> string(3) "10d" ["dt"]=> int(1471082400) ["temp_day"]=> int(18) ["temp_night"]=> int(13) ["temp_eve"]=> int(17) ["temp_morn"]=> int(15) ["wind_speed"]=> int(2) ["wind_deg"]=> int(282) ["humidity"]=> int(0) } [6]=> object(stdclass)#543 (9) { ["w_ico"]=> string(3) "10d" ["dt"]=> int(1471168800) ["temp_day"]=> int(20) ["temp_night"]=> int(16) ["temp_eve"]=> int(19) ["temp_morn"]=> int(16) ["wind_speed"]=> int(6) ["wind_deg"]=> int(201) ["humidity"]=> int(0) } } } 

this weather 5 days ahead, try parse this:

foreach ($w $key=> $value) {  echo $value['weather'][0]['dt'].'<br>';   } 

what wrong?

$w object , $w->weather array. should iterate array in foreach. also, each element of array object too. other thing don't need key inside foreach.

try this:

foreach ($w->weather $value) {  echo $value->dt.'<br>';   } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -