note 75319 added to function.array-search

From: Date: Wed, 23 May 2007 17:14:46 +0000
Subject: note 75319 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-126852@lists.php.net to get a copy of this message
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. ---- Server IP: 69.39.81.135 Probable Submitter: 204.154.43.244 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/75319 Del: integrated -- https://master.php.net/note/delete/75319/integrated Del: useless -- https://master.php.net/note/delete/75319/useless Del: bad code -- https://master.php.net/note/delete/75319/bad+code Del: spam -- https://master.php.net/note/delete/75319/spam Del: non-english -- https://master.php.net/note/delete/75319/non-english Del: in docs -- https://master.php.net/note/delete/75319/in+docs Del: other reasons-- https://master.php.net/note/delete/75319 Reject -- https://master.php.net/note/reject/75319 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126852) next »