dk4210 Posted January 12, 2012 Share Posted January 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254895-grabbing-an-array-from-a-function/ Share on other sites More sharing options...
premiso Posted January 12, 2012 Share Posted January 12, 2012 echo "Lat: " . $all_address2['latitude'] . " Long: " . $all_address2['longitude']; Simply by understanding how arrays work. Quote Link to comment https://forums.phpfreaks.com/topic/254895-grabbing-an-array-from-a-function/#findComment-1306959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.