1

I'm trying to slice a multi-array in php. I'm using google's geo-location api and I've managed to get it to return lat,lng and accuracy. I've used

$message =  json_decode($result, true);

To convert the Json into an array. The problem I have is that I have the results in this form:

Array ( [location] => Array ( [lat] => 10.1453652 [lng] => 0.2338764 ) [accuracy] => 33 ) 

and I can't figure out how to extract the lat and lon. Can anyone help?

2
  • 2
    echo $message["location"]["lat"] for lat. I guess you can understand how to get the lng... Commented May 15, 2019 at 13:19
  • You are a legend, thank you. It would be embarrassing for me to tell how how long I've been struggling with this, but let's just say it's been far too long! Commented May 15, 2019 at 13:23

2 Answers 2

1

Try the following code:

echo $message['location']['lat'];

Sign up to request clarification or add additional context in comments.

1 Comment

Do or do not. There is no "try". A good answer will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO.
0

It's simple, if not what you are expected, its straight forward

echo $message['location']['lat'].' '.$message['location']['lng'];

Working demo.

2 Comments

The sandbox is so helpful, thanks. I'm learning a ton today
@matt3526 Happy to help. To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.