Jump to content

Grabbing an array from a function


dk4210

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/254895-grabbing-an-array-from-a-function/
Share on other sites

Archived

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

×
×
  • Create New...

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.