PHP 手冊
上一頁 |  | 下一頁

# empty

(PHP 3, PHP 4, PHP 5 )

empty -- Determine whether a variable is empty

## Description

bool empty ( mixed var)

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.

示範 1. A simple empty() / isset() comparison.

`<?php $var = 0; // 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'; } ?>`

> 備注:由於這是一個語言結構、而不是函數，所以不能以變數函數的方式來呼叫。

> 備注: empty() only checks variables as anything else will result in a parse error. In otherwords, the following will not work: empty(addslashes($name)).

See also isset(), unset(), array_key_exists(), count(), strlen(), and the type comparison tables.

上一頁 | 最開頭 | 下一頁
doubleval | 上一層 | floatval