← All languages
PHP function of the day

empty

Determine whether a variable is empty.

Description

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.

Arguments

NameDescriptionOptional
var The variable or expression to check. No

Example

var_dump(empty(''));     // true
var_dump(empty(0));     // true
var_dump(empty('abc')); // false

Reference