I'm trying to get to a certain value using foreach (which I believe is the best way, performance-wise, as of know of)
[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
)
)
)
)
I'm trying to get latitude and longitude. But keep in mind that I will have more than just [0] => stdClass Object
. There will be multiple numbers. I know I can do something like $response->businesses[0]->location or some sort, but that only gets the 0
key, I need to be able to foreach the keys to get it.
Can someone help me do a foreach on this?
for example I'm doing this so far...
foreach($response->businesses->location as $llk=>$coordinate){
if($llk === "coordinate"){
$selected_lat = $coordinate->latitude;
$selected_lng = $coordinate->longitude;
}
}
So far its giving me errors.
Thanks!