I'm getting JSON data back like this:
{
"destination_addresses": [
"67-89 Pacific St, Brooklyn, NY 11201, USA"
],
"origin_addresses": [
"566 Vermont St, Brooklyn, NY 11207, USA"
],
"rows": [
{
"elements": [
{
"distance": {
"text": "6.5 mi",
"value": 10423
},
"duration": {
"text": "35 mins",
"value": 2076
},
"status": "OK"
}
]
}
],
"status": "OK"
}
I need to get the distance value and duration value as variables.
So, I know I need to decode this JSON:
$distance_data = json_decode($output);
And I've tried a ton of variations like:
$duration_value = $distance_data['rows']['elements']['duration']['value']);
But I know this isn't right. Can someone point me in the right direction?
$distance_data = json_decode($output, true); $distance_data['rows'][0]['elements'][0]['duration']['value']. Note: if you don't passtrueas 2nd paramater to json_decode, the result will be stdObject instead of array.