PHP
var_dump(0 == null)
//ture
javascript
console.log(0 == null)
//false
Why 0==null in PHP? Isn’t 0 a numerical value?
迷茫2017-06-17 09:17:17
The reason is that variables are stored in C language structures in PHP. Empty strings, NULL, and false are all stored with a value of 0.
null, 0, and false are all judged as 0 without distinguishing types. Logical false means false
过去多啦不再A梦2017-06-17 09:17:17
See the PHP manual, the picture below is taken from the PHP manual
This table shows the processing of the left and right operators by PHP binary operators.
It can be seen that 0 == null
, one operator is a number, and the other operator is null
, which conforms to the second case in the table, so according to the description, both sides are converted into corresponding Boolean values at the same time, that is Say 0
and null
are converted to false
, so false == false
is true
.