I have a case where I may recive one of two json objects, in this case from either the google geocode api, or the places api.
Acccessing values from the geocoding api it will look like this:
$coordinates = $data->results[0]->geometry->location;
$cache_value['lat'] = (string) $coordinates->lat;
$cache_value['lng'] = (string) $coordinates->lng;
and an almost identical structure for places.
$coordinates = $data->result->geometry->location;
$cache_value['lat'] = (string) $coordinates->lat;
$cache_value['lng'] = (string) $coordinates->lng;
In my code I've two functions to handle each case, but they are almost idential with the exception of the result vs results[0] and I'd like to combine them. I've tried to passing a varriable but it throws errors:
$result = ($place) ? 'result' : 'results[0]';
$coordinates = $data->$result->geometry->location;
Gives the following:
Notice: Undefined property: stdClass::$result[0]
I'd like to know the correct syntax to achive what im after, and any pointers on nominclature, as Im afraid this question title is a bit inpercise.
'results[0];a typo?