Re: Question about array_search

From: Date: Mon, 11 Oct 2004 17:06:24 +0000
Subject: Re: Question about array_search
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-199210@lists.php.net to get a copy of this message
Brian Dunning wrote:
Say I'm trying to add a value to an array, only if it's not already in there somewhere; so I do an array_search to see. The problem is that if the item is at index 0 in the array, array_search gives the same answer as if it's not in there at all.
No it doesn't. If the value is not there, it returns FALSE. If it's at index zero, then it returns zero. if($a === FALSE) { echo 'a is false'; } elseif($a === 0) { echo 'a is zero'; } Read here for an explanation of the above: http://us2.php.net/manual/en/language.operators.comparison.php -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#199210) next »