note 50752 deleted from function.in-array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter:  

----

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.