empty-checks if a variable is empty
Report a bug description
BOOL Empty (mixed $var)
If Var is a non-null or nonzero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty and return TRUE if Var is empty.
Empty () is the antonym of (Boolean) Var, except that it does not produce a warning when the variable has no value. See Convert to Boolean for more information.
Example #1 A simple comparison of empty () and isset ().
Copy CodeThe code is as follows:
$var = 0;
The result is true because the $var is empty
if (empty ($var)) {
Echo ' $var is either 0 or isn't set at all ';
}
The result is false because the $var has been set
if (!isset ($var)) {
Echo ' $var is not set at all ';
}
?>
Note: Because it is a language constructor and not a function, it cannot be called by a mutable function.
Note:
Empty () detects only variables and detects anything that is non-variable will result in parsing errors. In other words, the statement behind will not work: Empty (Addslashes ($name)).
The following things is considered to be empty:
"" (An empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
Null
FALSE
Array () (an empty array)
var $var; (a variable declared, but without a value in a class)
Understanding of "empty arrays": Array () (an empty array)
Copy CodeThe code is as follows:
$array 1=array ();
Print_r ($array 1);
if (Empty ($array 1)) {
Echo ' is an empty array (an empty array) for empty ();
}
else{
Echo ' is a non-empty array (an Noempty array) for empty ();
}
?>
displaying results: ######################
Array
(
)
For empty () is an empty array
###############################
$array 1=array ();
$array 1[]= ';
Print_r ($array 1);
if (Empty ($array 1)) {
Echo ' is an empty array (an empty array) for empty ();
}
else{
Echo ' is a non-empty array (an Noempty array) for empty ();
}
?>
displaying results: ######################
Array
(
[0] = =
)
is a non-empty array (an Noempty array) for empty ()
//###############################
This is not an empty array, because it has an element that is a null character (""), to be aware of the difference from the null character ("" (An empty string));
http://www.bkjia.com/PHPjc/324571.html www.bkjia.com true http://www.bkjia.com/PHPjc/324571.html techarticle empty-Checks if a variable is empty report a bug describes bool empty (mixed $var) If Var is a non-null or nonzero value, empty () returns FALSE. In other words, "", 0, "0" 、...