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

前端 未结 9 1810
佛祖请我去吃肉
佛祖请我去吃肉 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 02:53

    You should use === instead of ==, because the ordinary operator does not compare the types. Instead it will attempt to typecast the items.

    Meanwhile the === takes in consideration type of items.

    • === means "equals",
    • == means "eeeeh .. kinda looks like"

提交回复
热议问题