The PHP function in_array(...)
"checks if a value exists in an array".
But I'm observing a very strange behavior on handling strings (PHP v7.0.3
). This code
$needle = 'a';
$haystacks = [['a'], ['b'], [123], [0]];
foreach ($haystacks as $haystack) {
$needleIsInHaystack = in_array($needle, $haystack);
var_dump($needleIsInHaystack);
}
generates following output:
bool(true)
bool(false)
bool(false)
bool(true) <- WHAT?
The function returns true
for every string
$needle
, if the $haystack
contains an element with the value 0
!
Is it really by design? Or is it a bug and should be reported?