PHP's variable type leniency
<p>The most recent comment on PHP's <code>in_array()</code> help page (<a href="http://uk.php.net/manual/en/function.in-array.php#106319" rel="nofollow">http://uk.php.net/manual/en/function.in-array.php#106319</a>) states that some unusual results occur as a result of PHP's 'leniency on variable types', but gives no explanation as to why these results occur.  In particular, I don't follow why these happen:</p>

<pre><code>// Example array

$array = array(
    'egg' =&gt; true,
    'cheese' =&gt; false,
    'hair' =&gt; 765,
    'goblins' =&gt; null,
    'ogres' =&gt; 'no ogres allowed in this array'
);

// Loose checking (this is the default, i.e. 3rd argument is false), return values are in comments
in_array(763, $array); // true
in_array('hhh', $array); // true
</code></pre>

<p>Or why the poster thought the following was strange behaviour</p>

<pre><code>in_array('egg', $array); // true
in_array(array(), $array); // true
</code></pre>

<p>(surely 'egg' does occur in the array, and PHP doesn't care whether it's a key or value, and there is an array, and PHP doesn't care if it's empty or not?)</p>

<p>Can anyone give any pointers..?</p>
