Why does PHP consider 0 to be equal to a string?

前端 未结 9 1795
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 02:41

I have the following piece of code:

$item[\'price\'] = 0;
/* Code to get item information goes in here */
if($item[\'price\'] == \'e\') {
    $item[\'price\'         


        
9条回答
  •  广开言路
    2020-11-22 03:11

    The == operator will try to match values even if they are of different types. For instance:

    '0' == 0 will be true
    

    If you need type comparison as well, use the === operator:

    '0' === 0 will be false
    

提交回复
热议问题