Re: PHP 4.0 Bug #9337 Updated: make in_array return key, if searched value was found
| From: | Jason Greene | Date: | Mon, 19 Feb 2001 17:57:00 +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 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-46936@lists.php.net to get a copy of this message | ||
> 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.
-Jason
----- Original Message -----
From: "Andrei Zmievski" <andrei@ispi.net>
To: "Jason Greene" <jason@inetgurus.net>
Cc: "André Langhorst" <andre@php.net>; "PHP Development"
<php-dev@lists.php.net>
Sent: Monday, February 19, 2001 11:50 AM
Subject: Re: [PHP-DEV] PHP 4.0 Bug #9337 Updated: make in_array return key, if searched value was
found
> On Mon, 19 Feb 2001, Jason Greene wrote:
> > Some of my thoughts:
> > 1. if you change the return value of in_array to return the key, you can get a false error
> > in your if statement, imagine if in_array found the element in key 0? : )
> > 2. I would say that returning a key is a bit more useful then an option that does not
> > reset the internal pointer or not, though
I
> > can see a use of it
> >
> > I do agree that having too many parameters is a bad thing, but if this is a concern what
> > about making another function?
> >
> > There seems to be a large desire to see the key of in_array (see the haystack comment in
> > docs)
>
>
> -Andrei
> * The future is not what it used to be. *
>