The most recent comment on the PHP help page in_array()( http://uk.php.net/manual/en/function.in-array.php#106319 ) indicates that some unusual results result from the PHP 'leniency to variable types', but gives no explanation why these results occur. In particular, I do not understand why this happens:
$array = array(
'egg' => true,
'cheese' => false,
'hair' => 765,
'goblins' => null,
'ogres' => 'no ogres allowed in this array'
);
in_array(763, $array);
in_array('hhh', $array);
Or why did the poster think the following about strange behavior
in_array('egg', $array); // true
in_array(array(), $array); // true
(of course, an “egg” does occur in an array, and PHP does not care whether it is a key or value, and there is an array, and PHP does not care if it is empty or not?)
Can anyone point to pointers ..?
Chrisw source
share