In PHP, can someone explain to me why this resolves to true:
'NONE' == 0
Because any non-numerical string cast to int will turn into 0.
If you don't want that to happen, use ===, the identical operator.
Read:
http://php.net/manual/en/language.operators.comparison.php
http://php.net/manual/en/types.comparisons.php
is_numeric('16 foo') is FALSE, e.g. a non-numerical string and typecasting it to int will turn it into 16, not 0.Because the string is 0 when evaluated in a number context. Quoting:
If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.
So it depends on what the string contains.
Also, see the chapter on Type Juggling and Type Comparison in the PHP Manual.
('false' == false) is false, ('false' == true) is true.('10' == 10) and ('0xFF' == 255) and ('16 foo' == 16) is all true.