-1

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.

  • 3
    Have you gone through https://www.php.net/manual/en/language.types.type-juggling.php yet? – CBroe Aug 29 '23 at 10:20

1 Answers1

0

"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.

Harry B
  • 2,864
  • 1
  • 24
  • 44