Jump to content

Archived

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

clarencek

Array Help, Serialize/unserialize

Recommended Posts

Hi,

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

<?php

error_reporting(E_ALL);

// 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>';
print_r($phpobj);
echo '</pre>';


?>


The output of this is as below:

Array
(
[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
[City] => SUNNYVALE
[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:
$phpobj['ResultSet']['Result']['Latitude']

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.