var_export('as1223' == 0); // true ;) 

It seems to me alone that this is not true?

2 answers 2

There are a lot of illogical things in php, if you hope that it will guess your thoughts. Do not compare variables of different types. And if you compare, then please kindly study exactly how the interpreter does the casting.

In this case, the string is converted to a integer, and then the comparison occurs. Therefore, for example, the expression

 var_export('1as1223' == 0); 

will already be false.


Always first type the types if you are comparing different types of data.

    That's right, when performing a comparison operation, both parties are reduced to a single type in this case, the int is obtained (int) "as1223" is 0, so the equality 'as1223' == 0 is true. At the same time, 'as1223' == ' 0 'returns FALSE, since both operands are strings.

    • '1as122' === 0; // false - stasQa