note 57348 added to function.in-array
| From: | tyron at x-plosive dot net | Date: | Sat, 01 Oct 2005 00:48:04 +0000 |
| Subject: | note 57348 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96106@lists.php.net to get a copy of this message | ||
It seems that in_array() always returns TRUE if you are looking for the number 0, no matter whether
it's in the array or not. Example:
<?php
$arr = array ("mom", "dad", 2, 8);
if (in_array(0, $arr)) echo "found it";
?>
This will indeed output "found it". This does not occur with the needle being FALSE or
"0" or any other integer I tested and it does not occur with an empty array.
array_search(0, $arr) leads to a similar result: It will always return the number 0 (not FALSE).
I'm not sure whether this is a bug or whether I'm just not getting a deeper meaning here.
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57348
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57348&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57348&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57348&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57348&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57348&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57348&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57348&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57348&report=yes
Search -- http://master.php.net/manage/user-notes.php