empty-Check if a variable is empty
Statement a bug description
BOOL Empty (mixed $var)
Empty () returns FALSE if Var is a non-null or Non-zero value. In other words, "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any attributes will be considered empty and TRUE if Var is empty.
The empty () is the antonym of (Boolean) Var, except that the argument does not produce a warning when the variable does not have a value. See Convert to Boolean to get more information.
Example #1 A simple comparison of empty () and isset ().
Copy Code code as follows:
<?php
$var = 0;
The result is true because the $var is empty
if (empty ($var)) {
Echo ' $var is either 0 or not set at all ';
}
The result is false because the $var has been set
if (!isset ($var)) {
Echo ' $var is isn't set at all ';
}
?>
Note: Because it is a language constructor and not a function, it cannot be called by a variable function.
Note:
Empty () detects only variables, and detecting anything that is not a variable will result in parsing errors. In other words, the following statement will not work: Empty (Addslashes ($name)).
The following things are 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 array": Array () (an empty array)
Copy Code code as follows:
<?php
$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 ();
}
?>
//Display results: ######################
Array
(
)
//empty array
for empty () ###############################
<?php
$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 ();
}
?>
//Show Results: ######################
Array
(
[0] =>
)
//For Empty () is a non-empty array ( An noempty array)
//###############################
//This is not an empty array, because it has an element of NULL character (""), note and null character ("" (An empty string) difference;