PHP does not understand a lot of PHP 0, "", the difference between null and false, these differences can sometimes affect the correctness and security of data judgment, the test run of the program caused a lot of trouble.
Let's look at an example:
<?
$STR 1 = null;
$str 2 = false;
echo $str 1== $str 2? ' Equal ': ' Not equal ';
$str 3 = "";
$str 4 = 0;
Echo $str 3== $str 4? ' Equal ': ' Not equal ';
$str 5 = 0;
$str 6 = ' 0 ';
echo $str 5=== $str 6? ' Equal ': ' Not equal ';
$str 7=0;
$str =false;
echo $str 7== $str 8? ' Equal ': ' Not equal ';
?>
Operation Result:
Equal, equal, unequal, equal.
The reason is that in PHP the variables are stored in the C language structure, and the empty string and null,false are stored with a value of 0, where the struct has a zend_uchartype, a member variable that is used to hold the type of the variable, and the type of the empty string is string, The type of NULL is Null,false is Boolean.
This can be used with echo GetType ("); and Echogettype (NULL); To print it out! the = = = operator is not only the comparison value, but also the comparison type, so the third one is false!
So it can be said that = = = is equal to the following function:
function eq ($v 1, $v 2) {
if ($v 1 = = $v 2&&gettype ($v 1) ==gettype ($v 2)) {
return 1;
} else {
return 0;
}
}
So the empty string ('), False,null and 0 are values equal and the type is different!
Attention:
Null is a special type.
Null in both cases
1. $var = NULL;
2. $var;
3. "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty, and if Var is null, the TR is returned.
PHP null o false '