empty — Check whether a variable is empty
Report a bug Description
bool empty ( mixed $var )
If var is a non-empty or non-zero value, empty() returns FALSE. In other words, "", 0, "0", NULL, FALSE, array(), var $var; and objects without any properties will be considered empty, and TRUE is returned if var is empty.
In addition to not generating a warning when the variable is not set, empty() is the antonym of (boolean) var. See Converting to Boolean for more information.
Example #1 A simple comparison of empty() and isset().
Copy the code The code is as follows:
$var = 0;
// The result is true because $var is empty
if (empty($var)) {
echo '$ var is either 0 or not set at all';
}
// The result is false because $var has been set
if (!isset($var)) {
echo '$var is not set at all';
}
?>
Copy code The code is as follows:
$array1=array();
print_r($array1);
if(empty($array1)){
echo 'is an empty array for empty() array)';
}
else{
echo 'a noempty array for empty()';
}
?>
//Display result: ########## ############
Array
(
)
//For empty(), it is an empty array
################## ############
$array1=array();
$array1[]='';
print_r($array1);
if(empty($array1) ){
echo 'An empty array for empty()';
}
else{
echo 'An empty array for empty()';
}
?> ;
//Display results: #####################
Array
(
[0] =>
)
//For empty() Said to be a noempty array
//##############################
//This is not empty Array, because it has an element that is an empty character (""), please pay attention to the difference from an empty character ("" (an empty string));
The above introduces eigendecomposition php empty to check whether a variable is empty, including the content of eigendecomposition. I hope it will be helpful to friends who are interested in PHP tutorials.