The differences between is_null empty isset and unset in php are described in detail

  • 2020-06-01 08:37:31
  • OfStack

is_null, empty, isset, unset let's look at the descriptions of these four functions first.

isset to determine if the variable already exists (configuration)
unset deletes (releases) the variable
empty determines whether the variable is empty
is_null determines whether the variable is NULL
ok, it's already started. So at the beginning, of these four functions, except unset, the other three are judgment functions, unset is out first, because he can't make a mistake, is_null, we can view it as! isset is an inverse operation of isset. The following table can clearly illustrate the relationship between them:


 variable                           empty          is_null          isset
 $a= ""                        true               false              true
 $a=null                     true               true              false
 var $a                      true              true               false
 $a=array()               true               false              true
 $a=false                   true               false              true
 $a=15                      false              false               true
 $a=1                        false              false               true
 $a=0                        true               false               true
 $a= " 0 "                      true               false                true
 $a= " true "                 false               false              true
 $a= " false "                false               false               true


From this, we can find that as long as the variable is "or" or 0, or false and null, empty will return true, and isset is to judge whether the variable exists or not. As long as the variable is not null or not assigned, the return result is true, and is_null is exactly the opposite result of isset.

Of course, if you just want to do the following work:
echo! isset ($_GET [' a ']); // if the value of the variable a is not available
echo empty ($_GET [' a ']); // if the value of the variable a is empty

So it turns out to be all 1, and you can use both.


Related articles: