Re: PHP 4.0 Bug #9337 Updated: make in_array return key, if searched value was found

From: Date: Tue, 20 Feb 2001 14:27:59 +0000
Subject: Re: PHP 4.0 Bug #9337 Updated: make in_array return key, if searched value was found
References: 1 2 3 4 5 6 7 8 9  Groups: php.dev 
Request: Send a blank email to php-dev+get-47063@lists.php.net to get a copy of this message
On Tue, 20 Feb 2001, Stig Venaas wrote: > Not quite sure we need array_find(). If we can have in_array() set > the array pointer to point to the entry found, one can get the key > by using key(). If in_array() also searches from the pointer onwards, > one can find all entries with the value by doing: > > reset($arr); > while (in_array($val, $arr)) { > $keys[] = key($arr); > next($arr); > } in_array() used to move the pointer to the entry found, but people complained about it so I remove it... :) > I would prefer this rather then adding array_find() I think. If we > add array_find() I want similar functionality there. If not, I would > like an option for returning an array with all entries with the value. You can use array_keys($array, 'value') for that. -Andrei "The galaxy is, in other words, an immensely, intrinsically, and inexhaustibly interesting place." -- Iain M. Banks

« previous php.dev (#47063) next »