On Mon, Feb 19, 2001 at 12:02:48PM -0600, Andrei Zmievski wrote:
> On Mon, 19 Feb 2001, Jason Greene wrote:
> > > We can change in_array() to return the the key if it's found, and false
> > > if it's not, but imagine all the scripts it would break..
> > about 1/4th of mine : )
> >
> > Well I think the basic problem is that people are using in_array against its
>intention.
> > It is a Boolean function, and that really shouldn't be changed. We could create
>another
> > function that is more designed for searching? perhaps array_find? I wouldn't mind
>spending time on this if agreed upon.
>
> Could be done. The way I'd do it is have one php_in_array() C function
> that gets parameters passed through from in_array() and array_find() as
> well as a flag indicating whether to just return true/false or the
> actual key.
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);
}
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.
Stig
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]