Could someone explain to me why that is true?
in_array('', array(0,1,2));
Because, as said in the docs:
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
Searches haystack for needle using loose comparison unless strict is set.
... and '' == 0
is true in PHP. If you want to use strict comparison, just call in_array()
with three params:
in_array('', array(0, 1, 2), true); // false
... so the types will be checked as well, and String ''
won't have a chance to match against Numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With