Re: PHP 4.0 Bug #9337 Updated: make in_array return key, if searched value was found
| From: | Andrei Zmievski | Date: | Mon, 19 Feb 2001 18:02:48 +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 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-46937@lists.php.net to get a copy of this message | ||
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.
-Andrei
"The human brain is a wonderful thing. It starts working the moment you
are born, and never stops until you stand up to speak in public. " -- Sir
George Jessel