84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
PHP
var_dump(0 == null) //ture
javascript
console.log(0 == null) //false
Why 0==null in PHP? Isn’t 0 a numerical value?
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
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.
0 == null
null
0
false
false == false
true
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
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 isnull
, 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 Say0
andnull
are converted tofalse
, sofalse == false
istrue
.