Let's go over the empty and isset empty-check if a variable is empty "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty, and if VAR is null, returns TRUE if the isset-detects whether the variable is set, and is not NULL. That is: The variable is not set and returns false; variable is null, return false the PHP manual explains the comparison clearly, but if a variable is not set, what result does empty return? [PHP] Var_dump (Empty ($undefined)); Var_dump (Empty ($undefined)); The result is: BOOL (true) is visible and empty can also be used to detect whether the variable is set. So should we use empty instead of isset? I think if only to judge a variable exists, then the use of isset, because the meaning of isset is clear, is to do this use, but also conducive to the reading of the code. When it is necessary to determine the existence of variables, and the judgment variable is not 0, ", empty array, etc., you can use [PHP] if (!empty ($var)) instead of if (Isset ($var) &&!empty ($var)) if (!empty ($var)) Instead of if (Isset ($var) &&!empty ($var)) when you want to determine whether a variable is NULL, you must not use Isset. Here are some more things: Isset and empty performance? In fact, isset and empty performance are very good, the difference is not small. Also say that they are all statements, not functions, want to look specifically at this aspect of the content, you can see the bird brother of this article "the difference between Isset and is_null" statement can not be called by the variable function, in addition, in isset and empty can not accept the function of the return value as a parameter, For example, this is not possible [PHP] Empty (intval (' 3 ')); Fatal Error:can ' t use function return value in write context empty (Intval (' 3 ')),//fatal Error:can ' t use function retur n value in write context However, the current release of PHP5.5 supports this feature, which is the ability to use arbitrary expressions in empty: [PHP] FuNction Always_false () {return false;} if (Empty (Always_false ())) {echo "This would be printed.\n";} function Always_fal Se () {return false;} if (Empty (Always_false ())) {echo "This would be printed.\n";} Will output: This would be printed.
http://www.bkjia.com/PHPjc/477203.html www.bkjia.com true http://www.bkjia.com/PHPjc/477203.html techarticle let's go over the empty and isset. Empty checks if a variable is empty, 0, 0, NULL, FALSE, Array (), Var $var, and objects that do not have any properties will be considered empty, such as ...