PHP functions:empty() and isset() are both functions that determine whether the variable has been configured, but there are still certain differences when using them.
empty() function is used to test whether the variable has been configured. If the variable already exists, is not an empty string, or is nonzero, a false value is returned; otherwise, true is returned.
isset() function is used to test whether the variable has been configured. Returns true if the variable already exists. Other situations return a false value.
It can be seen from the definitions of the above two functions that empty() and isset() have something in common: both can determine whether a variable is empty, and both return boolean type, that is, true or false. The most obvious difference between them is that the Boolean value returned is exactly the opposite.
In addition, the biggest difference between them is the judgment of 0. If you use empty to judge, it will be considered to be empty, and if you use isset, it will be considered not to be empty. For example:
<?php var $a=0; //empty($a)返回true if(empty($a)){ echo "判断结果是空" } //isset($a)返回true if(isset($a)){ echo "判断结果不是空" } ?>
The above is the detailed content of PHP method to determine whether a variable is 0. For more information, please follow other related articles on the PHP Chinese website!