3 ms·
$needle = 0; $haystack = array('absolutely-any-value-in-the-world'); if ( in_array($needle, $haystack) ) { echo "I've heard of loose comparison but this migh
by jv22222 12y ago
$needle = 0;
$haystack = array('absolutely-any-value-in-the-world');
if ( in_array($needle, $haystack) )
{
echo "I've heard of loose comparison but this might be a little excessive.";
}
Note: I submitted it as a bug on php.net and the response was...
"Fundamental bugs are easy to find when you don't read the documentation."
(Just in case this isn't clear, it was closed as NOT being a bug within 10 mins of submitting.)
Of course I did read the docs and was aware of the strict comparison but I don't want strict comparison I just want it to work as expected, ie the value on the left matches the value in an array as long as it looks the same. So I would expect.. 0 to match '0', or 12345 to match '12345' but would not expect 0 to match any string value.
- deleted 12y ago[deleted]
- krapp 12y agoI agree with you - this is the sort of thing where you would expect strict comparison by default. Either it's in the array or it isn't. And I don't think i've ever used the strict comparison flag so now I have to go check all my projects... dammit PHP...