: This article mainly introduces the differences between 0, null, and false in php. For more information about PHP tutorials, see. Many php users do not understand the differences between 0, "", null and false in php. these differences sometimes affect the correctness and security of data judgment and cause a lot of trouble for program testing.
Let's take a look at an example:
$ Str1 = null;
$ Str2 = false;
Echo $ str1 = $ str2? 'Equality ': 'Unequal ';
$ Str3 = "";
$ Str4 = 0;
Echo $ str3 = $ str4? 'Equality ': 'Unequal ';
$ Str5 = 0;
$ Str6 = '0 ';
Echo $ str5 ===$ str6? 'Equality ': 'Unequal ';
$ Str7 = 0;
$ Str = false;
Echo $ str7 = $ str8? 'Equality ': 'Unequal ';
?>
Running result:
// Equal, equal, not equal, equal.
The reason is that the variables in PHP are stored in a C-language struct. both NULL and NULL, and false are stored in a value of 0. The struct contains a member variable such as zend_uchartype, it is used to save the variable type, while the empty string type is string, the NULL type is NULL, and false is boolean.
Echo gettype (''); and echogettype (NULL); can be used to print this point! The ===operator is not only a comparison value, but also a comparison type. Therefore, the third operator is false!
So it can be said that = is equal to the following function:
Functioneq ($ v1, $ v2 ){
If ($ v1 = $ v2 & gettype ($ v1) = gettype ($ v2 )){
Return1;
} Else {
Return0;
}
}
Therefore, NULL strings (''), false, and NULL and 0 are of the same value and different types!
Note:
NULL is a special type.
NULL in both cases
1. $ var = NULL;
2. $ var;
3. "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attribute will be considered empty. If var is empty, returns TRUE.
The above describes the differences between "0", "null", and "false" in php, including some content. I hope my friends who are interested in the PHP Tutorial will be helpful.