Current Location: Home> Function Categories> empty

empty

Check if a variable is empty
Name:empty
Category:Variable processing
Programming Language:php
One-line Description:Check if the variable is empty.

Definition and usage

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()

Example

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

grammar

 empty ( variable ) ;
parameter describe
variable Required. Specifies the variable to check.
Similar Functions
Popular Articles