PHP bool false and numeric 0
Ext.: http://home.phpchina.com/space.php?uid=108724&do=blog&id=54899
PHP is a loose-type language, which means that the Boolean value false and the integer value 0 are treated the same (even C also treats 0 and false as equivalent). You can use the script to determine the equivalence between 0 and Boolean? False:
?
? $test _var = 0;
if ($test _var = = False) {
?? echo "Yes";
?} else{
?? echo "No";
?}
?
?
Output: Yes
?
_________________________________________________________________________________
?
? $test _var = 0;
? if ($test _var!== false) {
?? echo "Yes";
?} else{
?? echo "No";
?}
?>
?
Output: Yes
?
_________________________________________________________________
?
The problem is that the Boolean value false and the integer value 0 are obviously different.
?
?
PHP has a GetType () function that gets the type of the variable. You can use the = = = Operator (bullish, with three equals). The difference between the and = = operators is that the operator compares both the value and the type of the data .
?
When the termination condition involves different variable types, use the. = = = and?! The = = operator is important for strong type checking.
?