Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    103
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Grabbing an array from a function

    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?

    Code:
    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

  • #2
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    Since you return an array, you have to treat it as an array.

    What happens if you print_r($all_addresses2); ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •