Determine whether a variable is empty.
The empty() language construct checks whether a variable is considered empty. A variable is empty if it does not exist or if its value is falsy. Falsy values include false, 0, 0.0, '0', '', null, and empty arrays.
Like isset(), empty() does not generate a notice for undefined variables, making it safe for checking array keys and object properties that may not exist.
As of PHP 5.5, empty() also works with expressions, not just variables. For example, empty(trim($str)) is valid. Note that empty() is a language construct, not a function.
| Name | Description | Optional |
|---|---|---|
var |
The variable or expression to check. | No |
var_dump(empty('')); // true
var_dump(empty(0)); // true
var_dump(empty('abc')); // false