bool empty ( mixed$var )
Judging whether a variable is empty or not, it can also be understood to determine if the variable is false. Returns a Boolean value of TRUE or false.
In addition to not generating a warning when a variable has no value empty ($var) Yes (bool) $var the opposite.
If $var can be converted to a Boolean false, the return value of empty () is true, otherwise, false is returned.
The following seven values, when converted to Boolean (same as bool), are considered false:
- Boolean-False itself
- Integral type 0
- Floating-point 0.0
- String ' 0 ' or ' 0 '
- Empty string ' or '
- An empty array () or []
- null or NULL
All other values are treated as true.
Var_dump ((bool) false);
Var_dump ((bool) 0);
Var_dump ((bool) 0.0);
Var_dump ((bool) ' 0 ');
Var_dump ((bool) ");
Var_dump ((bool) array ());
Var_dump ((bool) null);
?>
Empty returns true in seven cases of false, and the rest returns false.
bool isset ( mixed$var [, mixed$ ... ] )
Determines whether the variable is set, if the value of a variable is not NULL, then the variable is set and returns true; otherwise, returns false.
A variable is considered null in the following cases:
- is assigned a value of NULL
- has not been assigned or is defined
- Logged off by unset ()
Isset () returns false in three null cases, and the rest returns True.
The above describes the difference between empty and isset, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.