PHP empty() Function
PHP empty() Function
The empty() function in PHP determines whether the specified variable is empty or not. The specified variable is considered empty if it does not exist or if its value is equal to FALSE. This function does not generate a warning if the variable does not exist.
Syntax
empty ( mixed $var )
Parameter
var(required)- This parameter represents the variable that is to be checked.
Return
This function returns a Boolean value FALSE if the ‘var’ parameter exists and has a non-empty, non-zero value else it returns TRUE.
The empty values are as follows:
- "" (an empty string)
- 0 (0 as an integer)
- (0 as a float)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
Example 1
Output
False
Example 2
Output
$var is either 0, empty or is equals to False
Example 3
Output
$var is not empty. Its value is 1000
Example 4
Output
bool(false) bool(false) bool(true) bool(true)