note 98043 added to function.in-array
| From: | Svinto at osu1 dot php dot net | Date: | Sat, 22 May 2010 18:53:56 +0000 |
| Subject: | note 98043 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169519@lists.php.net to get a copy of this message | ||
in_array() will always return true if a value in the haystack is of type bool(true).
This always hold except when the needle is of type bool(false).
Code:
<?php
$haystack = array(true);
$needle = "anything except bool(false)";
$result = in_array($needle, $haystack);
var_dump($result); #Will always be true
?>
Solution:
run in_array() with strict set to true.
<?php
in_array($needle, $haystack, true);
?>
Tested on PHP 5.2.6
----
Server IP: 69.147.83.197
Probable Submitter: 83.254.65.38
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/98043
Del: integrated -- https://master.php.net/note/delete/98043/integrated
Del: useless -- https://master.php.net/note/delete/98043/useless
Del: bad code -- https://master.php.net/note/delete/98043/bad+code
Del: spam -- https://master.php.net/note/delete/98043/spam
Del: non-english -- https://master.php.net/note/delete/98043/non-english
Del: in docs -- https://master.php.net/note/delete/98043/in+docs
Del: other reasons-- https://master.php.net/note/delete/98043
Reject -- https://master.php.net/note/reject/98043
Search -- https://master.php.net/manage/user-notes.php