Jump to content


This topic is now archived and is closed to further replies.


Array Help, Serialize/unserialize

Recommended Posts


I'm using a Yahoo API to get geo data with the following php:



// output=php means that the request will return serialized PHP
$request = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=infofornyc&street=701+First+Street&city=Sunnyvale&state=CA&output=php';

$response = file_get_contents($request);

if ($response === false) {
die('Request failed');

$phpobj = unserialize($response);

echo '<pre>';
echo '</pre>';


The output of this is as below:

[ResultSet] => Array
[Result] => Array
[precision] => address
[warning] => The exact location could not be found, here is the closest match: 701 First Ave, Sunnyvale, 94089
[Latitude] => 37.416384
[Longitude] => -122.024853
[Address] => 701 FIRST AVE
[State] =>
[Zip] => 94089-1019
[Country] => US



This is probably a simple newbie question, but how do I access just the Latitude number? I want to grab that number and stick it in a mySQL database.

I thought it would be something like:

echo $phpobj[ResultSet[Result[1]]];

How do I access that variable.

Share this post

Link to post
Share on other sites
This will look a little messing, but I'm sure you can make it cleaner:

because it is an associative array you must use the corresponding string keys.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.