Comparing 2 different values returns true

This question already has an answer here:

  • Why does (0 == 'Hello') return true in PHP? 5 answers

  • Look at the details here:

    a string' == 0 also evaluates to true because any string is converted into an integer when compared with an integer. If PHP can't properly convert the string then it is evaluated as 0. So 0 is equal to 0, which equates as true.

    Also, in the official PHP documentation:

    To explicitly convert a value to integer, use either the (int) or (integer) casts. However, in most cases the cast is not needed, since a value will be automatically converted if an operator, function or control structure requires an integer argument.

    链接地址: http://www.djcxy.com/p/58586.html

    上一篇: 比较一个字符串和一个只有数字的字符串

    下一篇: 比较2个不同的值会返回true