First this is not a 2d array it is a single d array each element of which is
another array.
If you search the array for a value you won't find it as each element is an
array.
$layerDes[1][0] is not an element of $layerDes it is an element of the array
$layerDes[1].

As far as I know there is no built in way to search down this tree. I think
you'll need
To walk the array and check the first element of each e.g.

Foreach($layerDes as $count=>$array)
{       if ($array[0] == $searchstring)
        {       $key = $count;
                break;
        }
}

Tim Ward
www.chessish.com <http://www.chessish.com> 

        ----------
        From:  Pushkar Pradhan [SMTP:[EMAIL PROTECTED]]
        Sent:  14 May 2002 19:51
        To:  [EMAIL PROTECTED]
        Subject:  array_search in 2-d arrays

        I've a 2 D array and would like to search for vals. in the first
dimension
        only i.e.
        myArray[0][0]
        myArray[1][0]
        myArray[2][0]
        myArray[3][0]
        .
        .
        .
        and not in the elements myArray[0][1]....

        CODE:
        for($l = 0; $l < count($layer); $l++) {
           $key = array_search($layer[$l], $layerDes);   // $layerDes is 2-D
           $layer[$l] = $layerNames[$key];
        }
        My $key is undefined after execution, is it because the elements are
in
        $layerDes[i][0]?
        Using $key === also didn't help? Any ideas, thanks.

        -Pushkar S. Pradhan

        

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to