PHP empty() Function
❮ PHP Variable Handling Reference
Example
Check whether a variable is empty. Also check whether the variable is set/declared:
<?php
$a = 0;
// True because $a is empty
if (empty($a)) {
echo
"Variable 'a' is empty.<br>";
}
// True because $a is set
if (isset($a))
{
echo "Variable 'a' is set";
}
?>
Try it Yourself »
Definition and Usage
The empty() function checks whether a variable is empty or not.
This function returns false if the variable exists and is not empty, otherwise it returns true.
The following values evaluates to empty:
- 0
- 0.0
- "0"
- ""
- NULL
- FALSE
- array()
Syntax
empty(variable);
Parameter Values
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check |
Technical Details
Return Value: | FALSE if variable exists and is not empty, TRUE otherwise |
---|---|
Return Type: | Boolean |
PHP Version: | 4.0+ |
PHP Changelog: | PHP 5.5: Support for expressions, not only variables PHP 5.4: Non-numeric offsets of strings returns TRUE |
❮ PHP Variable Handling Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.