note 44492 added to function.array-search

From: Date: Sat, 07 Aug 2004 23:56:50 +0000
Subject: note 44492 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-74177@lists.php.net to get a copy of this message
array_search() has kind of hidden behaviour which comes from the way PHP compares values of different types (PHP is a type-loose language) - so called type juggling. for example : <?php $a=array(0,0,5,0,0); var_dump(array_search(true, $a)); ?> In the array there are only integers but we give a boolean value TRUE for be the needle. The result is that array_search() returns the first non-negative value in the haystack array. The same way if we pass FALSE it will return the first value that compared with FALSE gives TRUE - for example NULL <?php $a=array(1,NULL,5,0,0); var_dump(array_search(FALSE, $a)); ?> Returns: int(1) <-- the key of the NULL value ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44492 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44492&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44492&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#74177) next »