| 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, with empty and isset to detect whether the variable $id has been configured, both will return different values--empty think that there is no configuration, isset can obtain the value of $id:
?? $id=0;
?? Empty ($id)? print "It's empty.":p rint "it's $id.";?
???? Result: It ' s empty.
?? Print "
";
?? !isset ($id)? print "It's empty.":p rint "it ' s $id.";
???? Result: It ' s 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 1
?? if (!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
|