note 53745 added to function.in-array

From: Date: Sat, 11 Jun 2005 12:26:28 +0000
Subject: note 53745 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-90262@lists.php.net to get a copy of this message
If you have a multidimensional array filled only with Boolean values like me, you need to use 'strict', otherwise in_array() will return an unexpected result. Example: <? $error_arr = array('error_one' => FALSE, 'error_two' => FALSE, array('error_three' => FALSE, 'error_four' => FALSE)); if (in_array (TRUE, $error_arr)) { echo 'An error occurred'; } else { echo 'No error occurred'; } ?> This will return 'An error occurred' although theres no TRUE value inside the array in any dimension. With 'strict' the function will return the correct result 'No error occurred'. Hope this helps somebody, cause it took me some time to figure this out. ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53745 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53745&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53745&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53745&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53745&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53745&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53745&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90262) next »