empty() returns FALSE if var has a non-empty and non-zero value. In otherwords, "", 0, "0", NULL, FALSE, array(), var $var;, and objects with empty properties, are all considered empty. TRUE is returned if var is empty.
empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set. See converting to boolean for more information.
// Evaluates to true because $var is empty if (empty($var)) { echo '$var is either 0, empty, or not set at all'; }
// Evaluates as true because $var is set if (isset($var)) { echo '$var is set even though it is empty'; } ?>
Note: Because this is a language construct and not a function, it cannot be called using variable functions
Note: empty() only checks variables as anything else will result in a parse error. In otherwords, the following will not work: empty(addslashes($name)).
Deliver First Class Web Sites: 101 Essential Checklists Want to learn how to make your web sites usable and accessible? Want to ensure that your sites meet current best practice, without spending hours trawling through incomprehensible specifications and recommendations from dozens of different books, research papers, and web sites? Want to make sure that the sites you build are "right the first time," requiring no costly redevelopments?