note 98043 deleted from function.in-array by cmb
| From: | cmb@php.net | Date: | Sun, 15 Sep 2019 13:10:50 +0000 |
| Subject: | note 98043 deleted from function.in-array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212197@lists.php.net to get a copy of this message | ||
Note Submitter: Svinto
----
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