search

Home  >  Q&A  >  body text

Why is 0==null true in PHP?

PHP

var_dump(0 == null)
//ture

javascript

console.log(0 == null)

//false

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

phpcn_u1582phpcn_u15822788 days ago887

reply all(2)I'll reply

  • 迷茫

    迷茫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

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再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.

    reply
    0
  • Cancelreply