我想使用的foreach(我認爲這是最好的辦法,性能明智的,因爲知道的)Foreach循環數組和stdClass對象解決,獲取值
[businesses] => Array
(
[0] => stdClass Object
(
[rating] => 4
[location] => stdClass Object
(
[city] => Claremont
[display_address] => Array
(
[0] => 580 W First St
[1] => Claremont, CA 91711
)
[geo_accuracy] => 8
[postal_code] => 91711
[country_code] => US
[address] => Array
(
[0] => 580 W First St
)
[coordinate] => stdClass Object
(
[latitude] => 34.094112
[longitude] => -117.7250746
)
)
)
)
我去一定值試圖獲得經度和緯度。但請記住,我將不僅僅是[0] => stdClass Object
。會有多個號碼。我知道我可以做一些事情,如$ response-> business [0] - > location或某種排序,但只能得到0
鍵,我需要能夠通過foreach鍵來獲得它。
有人可以幫我做一個foreach嗎?
比如我這樣做是那麼遠,
foreach($response->businesses->location as $llk=>$coordinate){
if($llk === "coordinate"){
$selected_lat = $coordinate->latitude;
$selected_lng = $coordinate->longitude;
}
}
到目前爲止它給我的錯誤。
謝謝!
[stdClass object and foreach loops](http://stackoverflow.com/questions/950827/stdclass-object-and-foreach-loops) – Cullub 2016-02-08 21:44:18