note 75319 deleted from function.array-search by peehaa
| From: | peehaa@php.net | Date: | Fri, 07 Apr 2017 10:35:56 +0000 |
| Subject: | note 75319 deleted from function.array-search by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209004@lists.php.net to get a copy of this message | ||
Note Submitter: php5 site builder
----
If you encounter a situation where condition test is failing on the result of either array_search or
in_array, even when using "===" and "!==", make sure to set $strict = true in
your array_search() or in_array() function call.
A situation such as :
$arTemp[0] = 1;
$arTemp[1] = 0;
$arTemp[2] = 3;
$arTemp[3] = 5;
$sTempTest = 'BLAH';
$bResult = in_array($sTempTest,$arTemp);
$bResult2 = array_search($sTempTest,$arTemp);
var_dump($bResult);
var_dump($bResult2);
will result in :
boolean true
int 1
Using :
$bResult = in_array($sTempTest,$arTemp,true);
$bResult2 = array_search($sTempTest,$arTemp,true);
will yield :
boolean false
boolean false
This is necessary in any instance where you have an array value equal to the integer zero. As soon
as you put the zero in quotes or double quotes (a string), the evaluation works with in_array &
array_search without the $strict parameter being set.