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

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

    You are doing == which sorts out the types for you.

    0 is an int, so in this case it is going to cast 'e' to an int. Which is not parsable as one and will become 0. A string '0e' would become 0 and would match!

    Use ===

提交回复
热议问题