I\'m confused by something I just ran into in a script I was working on. I had the following:
function getPart($part)
{
$array = array(\'a\', \'b\', \'c\');
If you try to compare a string to a number, PHP will try to convert the string to a number. In this case, it fails to do so, since PHP can't convert "first" or "last" into a number, so it simply converts it to zero. This makes the check 0 == 0
, which is, of course, true. Use the identity operator, ===
, if you want PHP to not attempt to convert anything (so, the two operands must have the same value and be of the same type).