Re: testing array_search

From: Date: Sat, 12 Jun 2004 01:05:14 +0000
Subject: Re: testing array_search
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-188141@lists.php.net to get a copy of this message
On 06/11/04 17:17 Curt Zirzow spoke:
* Thus wrote Bob Lockie (bjlockie@lockie.ca):
I'm having a very hard time testing array_search. $j = array_search( $i, $errList ); echo "j=" . $j; if (($j != false) && ($j >= 0)) {
<snip> mixed array_search ( mixed needle, array haystack [, bool strict]) Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise. </snip> When ever you see that a function that returns mixed with a possible FALSE Boolean value. You must always test your result as follows: if ($j !== FALSE) { // found an item } else { // no item found }
Ok, I supected it was a boolean thing. :-(

« previous php.general (#188141) next »