1

I have an array object below

33 => 'a:2:{ 
   s :8:"latitude";
   s:10:"39.3600586";
   s:9:"longitude";
   s:18:"-84.30993899999999";
}'

And here is the variable I'm using to get the value of that object

$events_location = $entries[1]['33'];

Is there a way to get just the value of either the latitude or longitude instead of everything in the single quotes?

Thanks!

2 Answers 2

2

What you have here is a serialized string. Unserialize it to access the key in the array:

$events_location = unserialize($entries[1]['33']);
echo $events_location['longitude'];
Sign up to request clarification or add additional context in comments.

Comments

0

This should be a comment but its a bit long.

The string you have shown us looks vaguely like part of a serialized php entity. But it's not. If you try to unserialize this you'll get an error. The underlying data appears to be a coordinate - but even ignoring the syntactic errors, the semantics of the structure are wrong.

Please check the source you transcribed this from. If you have not copied the original content here please amend your question.

If you have transcibed it correctly then go speak to whoever supplied you with this data and ask them to fix it.

4 Comments

I was able to unserialize successfully. What syntactic error are you referring to?
Then what you unserialized is not what you have shown us here.
This is true, what's in the first bracket is a looped variable.Thanks for clearing that up!
It's just a mistake due to re-formatting the value for display. The original serialized string, which didn't have the extra whitespace, is well-formed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.