Cases
The code is as follows |
Copy Code |
<?php $test = 0; if ($test = = ") { Echo ' <br/> in php, 0 is empty '; is output } if ($test = = = ") { Echo ' <br/> in php, 0 is empty '; Not to be output } if ($test ==null) { Echo ' <br/> in php, 0 is empty '; is output } if ($test ===null) { Echo ' <br/> in php, 0 is empty '; Not to be output } if ($test ==false) { Echo ' <br/> in php, 0 is empty '; is output } if ($test ===false) { Echo ' <br/> in php, 0 is empty '; Not to be output } ?> |
The reason is that in PHP, variables are stored in C-language structures, empty strings and null,false are all stored with a value of 0, where the struct has a zend_uchar type; Such a member variable, which 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 a Boolean.
This can be seen with Echo GetType ('); and Echo GetType (NULL); 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:
The code is as follows |
Copy Code |
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 attributes will be considered empty and TRUE if Var is empty.
Summarize
From the example above we can see that Null,0,false is false, and that "is an empty string is not a null value."