Home  >  Article  >  Backend Development  >  eigendecomposition php empty checks whether a variable is empty

eigendecomposition php empty checks whether a variable is empty

WBOY
WBOYOriginal
2016-07-29 08:47:131420browse

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';
}
?>


Note: Because it is a language constructor rather than a function, it cannot be called by variable functions.
Note:
empty() only checks for variables, checking anything that is not a variable will result in a parsing error. 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 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn