<?php
$test = 0;
if ($test = = ") {
Echo ' <br/> in php, 0 is empty '; is output
}
if ($test = = =) {
Echo ' <br/> in php, 0 is empty '; not 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 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 be output
}
?>
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_uchar type, 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 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 |
|
|
function eq ($v 1, $v 2) {
if ($v 1 = = $v 2 && GetType ($v 1) = = GetType ($v 2)) {
return 1;
} else {
return 0;
}
} |
PHP 0 differs from NULL null false