The code is as follows |
Copy Code |
$a = 0; This time Empty ($a) = = true; Isset ($a) = = true; $a = 1; This time Empty ($a) = = false; Isset ($a) = = true; Isset ($a) = = True when no $a is defined; Empty ($a) = = true; |
The common denominator is that empty () and isset () are variable processing functions that determine whether variables have been configured, precisely because they have a great similarity in the process of processing variables, leading to a lack of understanding of their relationship. The empty () and isset () of the two functions themselves will make the person more confused and put it in a different angle. The processing objects of empty () and isset () are no more than undefined variables, 0, empty strings.
If the variable is 0, then empty () returns True,isset () to return true;
If the variable is an empty string, then empty () returns True,isset () to return true;
If the variable is undefined, empty () returns True,isset () and returns flase;
Instance
The code is as follows |
Copy Code |
$a = 0; This time Var_dump (Empty ($a));/= = true; Var_dump (Isset ($a));/= = true;
$a = 1; This time Var_dump (Empty ($a));//= FALSE; Var_dump (Isset ($a));/= = true;
When a variable is not defined $bbbbbbbbbb, Var_dump (Isset ($BBBBBBBBBB));//= FALSE; Var_dump (Empty ($BBBBBBBBBB));/= = true; |
Instance
code is as follows |
copy code |
<?php /** * isset -detect whether the variable is set * returns True if the variable exists, otherwise returns false * * empty -Check whether a variable is empty * if the variable is non-null or Non-zero, empty () returns false **/ $is _ var = '; If (isset ($is _var)) { echo variable exists! <br/> "; } else { echo variable does not exist! <br/> "; } If (empty ($is _var)) { echo variable is empty! <br/> "; } else { echo variable is not empty! <br/> "; } ? |
Empty () determines whether a variable is "empty" and isset () to determine whether a variable has been set. It is this so-called "as the name implies" that I began with some detours: when a variable value is equal to 0 o'clock, empty () will also be set (True), so there will be some surprises. Originally, Empty () and isset (), although they are variable processing functions, 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 a variable value is 0,empty (), the variable equals null, which is equivalent to no setting.