NYCPHP Meetup

NYPHP.org

[nycphp-talk] Recursive Help?

Jiju Thomas Mathew lists at silmail.com
Sun Mar 25 22:57:03 EDT 2007


Hi Joseph,

it is the problem of using list(..) = each
Each - Return the current key and value pair from an array and advance the
array cursor

So your list($lat,$lng) = each($coords) will assign $lat = 0 and $lng =
($lat you passed), creating the weird output. Changing the function to as
shown below should clear your woes.


function nextCoord($coords, $usedCoords)
{
    $lat = (float)$coords[0];
    $lng = (float)$coords[1];


    if(in_array($lat.':'.$lng, $usedCoords))
    {
        $lat += 0.0005;
        $lng += 0.0005;
        return nextCoord(array($lat, $lng), $usedCoords );
    }
    $array = array($lat, $lng);
    print_r($array); // disable this after debug
    // return $array; // enable this after debug
}


-- 
Jiju Thomas Mathew
http://www.php-trivandrum.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070326/c95ae778/attachment.html>


More information about the talk mailing list