PHP - false == 0 but false != "00"

46 Views Asked by At

I had a problem with checking falsy conditions and don't understand how 'false' works.

I tested the code above,

echo (0 == false); //->true
echo ("0" == false); //->true
echo ("0" == 0); //->true
echo ("000000000000" == 0); //->true
echo ("000000000000" == false); //->false

And don't understand why the last result is false instead of true.

Thanks for your explanation.

1

There are 1 best solutions below

0
Harry B On

"000000000000" and "00" and indeed anything other than "0" are evaluated as true because they are treated as regular non-empty strings in PHP and therefore not considered as a falsy value. PHP will only evaluate "0" as false.