empty
Check if a variable is empty
empty()
function is used to check whether a variable is empty.
If the variable exists and is not empty, this function returns false
, otherwise true
.
The following values are considered empty:
0
0.0
"0"
""
NULL
FALSE
array()
Checks whether a variable is empty. Also check whether the variable has been set/declared:
<?php $a = 0 ; // The result is true, because $a is empty if ( empty ( $a ) ) { echo "variable 'a' is empty.<br>" ; } // The result is true because $a is set if ( isset ( $a ) ) { echo "variable 'a' is set" ; } ?>
Try it yourself
empty ( variable ) ;
parameter | describe |
---|---|
variable | Required. Specifies the variable to check. |