Many people have not considered the relationship between string () and NULL !! Now let me explain: Let's first look at an example: NULL; after running, we will find that the first is true, and the second is false! Why? In fact, both PHP hollow strings and NULL are stored as 0! And only compare, so
Many people have not considered the relationship between the string ('') and NULL !! Now let me explain: Let's first look at an example: ''= NULL; after running, we will find that the first is true, and the second is false! Why? In fact, both PHP hollow strings and NULL are stored as 0! And = only compare, so
Many people have not considered the relationship between the string ('') and NULL !!
Now let me explain:
Let's take a look at an example:
''= NULL;
''= NULL;
After running the command, the first value is true, and the second value is false!
Why?
In fact, both PHP hollow strings and NULL are stored as 0 values!
And = only compare the value, so the first is true! But why is the second option false !?
The reason is that the variables in PHP are stored in the C-language structure, where the structure has a zend_uchar type. Such a member variable is used to save the type of the variable, the empty string type is string, and the NULL type is NULL.
Echo gettype (''); and echo gettype (NULL); can be used to print this point! The ===operator is not only a comparison value, but also a comparison type. Therefore, the second operator is false!
So it can be said that = is equal to the following function:
function eq($var1, $var2) { if($var1 == $var2 && gettype($var1) == gettype($var2)) { return 1; } else { return 0; }}
So the NULL String (''), 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;
Summary:
Both string and NULL are stored as 0 values, so null = 0 = ''.
Null = 0 null = empty (true)
Null = 0 null = empty (not valid)
All of the following outputs are available:
if(0==null){echo "0null";echo "
";}if(null==''){ echo "nullkong";echo "
";}if(null !== 0){echo "abs null0";echo "
";}if('' == 0){echo "empty0";}