...

View Full Version : Grabbing an array from a function



dk4210
01-12-2012, 03:24 PM
Hello Guys,

I have a question

I have the following function that is located in a different file. I want to be able to use the $lat and $long in my main page how would I code it?



function toCoordinates($all_address)
{
$bad = array(
" " => "+",
"," => "",
"?" => "",
"&" => "",
"=" => ""
);
$all_address = str_replace(array_keys($bad), array_values($bad), $all_address);
$data = new SimpleXMLElement(file_get_contents("http://maps.google.com/maps/geo?output=xml&q={$all_address}"));
$coordinates = explode(",", $data->Response->Placemark->Point->coordinates);
return array(
"latitude" => $coordinates[0],
"longitude" => $coordinates[1]
);
}


Tried this but it didn't work

$all_address2 = toCoordinates($all_address);

echo "$all_address2;

Please advise...
Thanks, Dan

Kekke
01-12-2012, 06:50 PM
Since you return an array, you have to treat it as an array.

What happens if you print_r($all_addresses2); ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum