Consider the following PHP statements:
echo ( 0 == '' ? 1 : 0); // Output is 1
echo ('0' == '' ? 1 : 0); // Output is 0
The first will print 1, and the second will print 0. Shouldn't they both print 0? Is this expected behavior? I'm guessing its because the second is a string and the first is not, but I'd like another answer.
Read Loose comparisons with ==
In Php empty string, NULL and 0 are equal.
In second case '0' is another string, and '' is another. So you get result false.
"", 0, "0", False, array(), Null are all considered False in PHP.
You can use === to make them different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With