1

Possible Duplicate:
Why does (0 == ‘Hello’) return true in PHP?

<?php
echo ('names' == 0) ? 1 :0;
?>

Evaluates to TRUE

If I add an extra equals sign it will work, but this is counter intuitive.

<?php
echo ('names' === 0) ? 1 :0;
?>

Evaluates to FALSE

<?php
echo ('names' == FALSE) ? 1 :0;
?>

Evaluates to FALSE

Also found this: Why does 1234 == '1234 test' evaluate to true?

Community
  • 1
  • 1
Jay
  • 833
  • 7
  • 15

1 Answers1

3

The reason is that the numerical value of the string 'names' is 0, but the boolean value is true (as far as I know, any non-empty string that's not also '0' or something similar is equivalent to true in PHP).

Ynhockey
  • 3,845
  • 5
  • 33
  • 51
  • http://stackoverflow.com/questions/12151997/why-does-1234-1234-test-evaluate-to-true?rq=1 – Jay Jan 21 '13 at 12:06