About Empty ()
Empty () is used to check if a variable is empty. If the variable is a non-null or nonzero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty and return TRUE if Var is empty.
A simple comparison of empty () with Isset ().
Because this is a language structure and not a function, it cannot be called by a variable function.
Empty () detects only variables and detects anything that is non-variable will result in parsing errors. In other words, the statement behind will not work: Empty (Addslashes ($name)).
Empty to determine whether a variable is "empty", isset to determine whether a variable has been set. It is this so-called "as the name implies", so I began to take some detours: when a variable value equals 0 o'clock, empty () will also be set (True), so there will be some accidents. Originally, empty and isset are variable processing functions, they are used to determine whether the variables have been configured, they are a certain difference: empty will also detect whether the variable is empty, zero. When the value of a variable is 0,empty that the variable equals null, it is equivalent to no setting.
For example, the detection of $id variables, when $id = 0 o'clock, with empty and isset to detect whether the variable $id has been configured, both will return different values--empty think there is no configuration, isset can get the value of $id:
Test code
";! Isset ($id)? Print "It's empty." The value of ":p rint ' $id '." is $id. "; >
Program Run Result:
The variable $id is empty.
The value of the $id is 0.
This means that when we use the variable handler function, when the variable may appear with a value of 0, use empty to be careful, it is wiser to replace it with Isset.
When the URL trailing parameter of a PHP page appears id=0 (for example: test.php?id=0), try comparing:
if (empty ($id)) $id = 1; If id=0, the ID will also be 1if (!isset ($id)) $id = 1; If id=0, the ID will not be 1
The following code can be run separately to detect the above inference:
if (empty ($id)) $id =1; Print $id; Get 1
if (!isset ($id)) $id =1; Print $id; Get 0
http://www.bkjia.com/PHPjc/752588.html www.bkjia.com true http://www.bkjia.com/PHPjc/752588.html techarticle about Empty () empty () is used to check if a variable is empty. If the variable is a non-null or nonzero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, Array () 、...