0 == ” (zero is equal to ”)


Recently I faced one issue where I noticed that zero is being equal to empty string and my condition was being true.

    $a = 0;
    if($a == ''){
         echo 'Condition true';
    }else{
        echo 'Condition false';
    }
Advertisements

One thought on “0 == ” (zero is equal to ”)

  1. Make a habit to use === comparison operator instead of double equality. This not the only case where double equality operators fails there are dozens of cases.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s