Re: array_search and multi-dimensional arrays

From: Date: Tue, 14 Mar 2006 00:04:36 +0000
Subject: Re: array_search and multi-dimensional arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-231881@lists.php.net to get a copy of this message
looks like this works. Is there any problem with it that people can see? $c[1][]="Vietnam"; $c[1][]="China"; $c[1][]="Thailand"; $c[1][]="England"; $c[2][]="USA"; $c[2][]="Japan"; print_r($c); foreach($c as $key=>$value) { if(array_search("England",$value)) {
       echo $key;	
    }
} thanks, jonathan On Mar 13, 2006, at 3:54 PM, jonathan wrote:
I'd like to return the first key value in the following array such that England would return 1 rather than 3 which is the second key value. Any help would be greatly appreciated. $c[1][]="Vietnam"; $c[1][]="China"; $c[1][]="Thailand"; $c[1][]="England"; $c[2][]="USA"; $c[2][]="Japan"; print_r($c); // Array ( [1] => Array ( [0] => Vietnam [1] => China [2] => Thailand [3] => England ) [2] => Array ( [0] => USA [1] => Japan ) ) foreach($c as $row) {
    echo array_search("England",$row);
} // prints 3 -jonathan --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#231881) next »