Why is 0==null true in PHP?
phpcn_u1582
phpcn_u1582 2017-06-17 09:15:17
0
2
870

PHP

var_dump(0 == null)
//ture

javascript

console.log(0 == null)

//false

Why 0==null in PHP? Isn’t 0 a numerical value?

phpcn_u1582
phpcn_u1582

reply all(2)
迷茫

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梦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template