PHP Basics, some thing that is false and true at the same time!
Feb 14, 2012 · 1 minute readCategory: php
What can be true and false at the same time?
$a = "a";
$b = 0;
if($a == true && $b == false && $a == $b) {
echo "Passed";
}
This is because PHP tries to convert “a” to a numeric, as there is no numeric value it gets changed to zero. So 0 == 0 is true. At the same time the string “a” converted to boolean evaluates to true. 0 evaluates to false. While there isn’t an actual value that is both true and false that the same type, depending on the context a value may evaluate to true or false depending on what it is been compared to. To avoid problems like this, you should use triple equals (===) unless you know other wise.