Empty () function: mainly determines whether the variable is not empty or not 0. If the variable value is not null or not 0, true is returned; otherwise, false is returned.
Differences between empty () and isset () functions:
Empty () function: mainly determines whether the variable is not empty or not 0. If the variable value is not null or not 0, true is returned; otherwise, false is returned.
Description: bool empty (mixed $ var)
If var is a non-null or non-zero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, array (), var $ var; and objects without any attributes will be considered empty, if var is null, TRUE is returned.
When converted to boolean, the following values are considered FALSE:
- Boolean value FALSE
- Integer value 0 (0)
- Floating point value: 0.0 (0)
- Empty string and string "0"
- Array that does not contain any elements
- Objects that do not include any member variables (applicable only to PHP 4.0)
- Special type NULL (including unassigned variables)
- SimpleXML object generated from an XML document without any tags
Isset () function: mainly determines whether the variable has been set (not null). if it has been set, true is returned; otherwise, false is returned. it indicates bool isset (mixed $ var [, mixed $...])
Check whether the variable is set and not NULL.
If unset () is used to release a variable, it will no longer be isset (). If you use isset () to test a variable that is set to NULL, FALSE is returned. Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP.
Example 1:
$var; var_dump($var); //NULL echo ""; var_dump(empty($var)); //true; NULLecho ""; var_dump(isset($var)); //false; NULL
Example 2:
$ Var = '';
Var_dump ($ var); // string echo ""; var_dump (emptyempty ($ var); // true; the variable value is empty echo ""; var_dump (isset ($ var); // variable set; non-NILL