note 50752 added to function.in-array

From: Date: Wed, 09 Mar 2005 02:15:33 +0000
Subject: note 50752 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-86136@lists.php.net to get a copy of this message
I'd have to disagree with the previous poster. The behavior is not "completely as expected." If I do not know what data is in an array, and I search for the value "123abc", I certainly don't expect it to match the integer 123. I expect it to match the string "123abc," period. The needle should not be converted for the sake of comparison! In the case of a string in the haystack or needle, the other value should be converted to a string before comparison. This guarantees only equivalent values will be matched. This kind of behavior is the reason I always use === in PHP instead of ==. Too many things match otherwise. Luckily, the "strict" option here gives the right results. -Dan ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50752 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50752&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50752&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50752&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50752&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50752&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50752&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86136) next »