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

From: Date: Mon, 19 Feb 2001 17:48:34 +0000
Subject: Re: PHP 4.0 Bug #9337 Updated: make in_array return key, if searched value was found
References: 1 2 3 4  Groups: php.dev 
Request: Send a blank email to php-dev+get-46934@lists.php.net to get a copy of this message
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) -Jason ----- Original Message ----- From: "Andrei Zmievski" <andrei@ispi.net> To: "André Langhorst" <andre@php.net> Cc: "PHP Development" <php-dev@lists.php.net> Sent: Monday, February 19, 2001 11:36 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, André Langhorst wrote: > > How about using array_keys($array, $value) to find the key? > > obviously it is cheaper to let in_array return it and it is more php 4 > stylish, we have booleans, why not use them? > > if ($key=in_array()) do_someting_with_key($key); So, you suggest putting in 4th parameter? Then someone on php-general suggested a few months ago to put in another parameter that controls whether in_array() moves internal pointer or not.. Too many parameters. -Andrei * Power corrupts. Atomic power corrupts atomically. * -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#46934) next »