Home>

stop talking nonsense,Post the code directly to everyone.

<?php
  class test {}
  $a1=null;
  $a2="";
  //$a3 =
  $a4=0;
  $a5="0";
  $a6=false;
  $a7=array ();
  //var $a8;
  $a9=new test ();
  for ($i=1;$i<= 9;$i ++) {
    $s="a". $i;
    echo $i. ":";
    var_dump (isset ($$s));
    echo "<br />";
  }
  echo "<br />";
  for ($i=1;$i<= 9;$i ++) {
    $s="a". $i;
    echo $i. ":";
    var_dump (empty ($$s));
    echo "<br />";
  }

ps:The difference between empty () and isset () in PHP

For those new to php,The difference between empty () and isset () usage is difficult to figure out,The difference in their usage is really difficult to figure out without careful consideration.

Let's talk about their common ground first:

Can determine whether a variable is empty;

Both return boolean types, that is, true or false.

Here's the difference between their usage:

isset () is used to detect whether a variable is set,Can only be used for variables,Because passing any other parameter will cause a parsing error.To check if the constant is set,Use the defined () function. If a variable has been released using unset (),It will no longer be isset (). Using isset () to test a variable that is set to null will return false. (Note that a null byte ("\ 0") is not equivalent to PHP's null constant)

empty () is used to check if a variable is empty.

The biggest difference between them is the judgment of 0. If the judgment is empty, it will be considered as empty.Isset is not considered empty,for example:

<?php
     var $a=0;
      //empty ($a) returns true
      if (empty ($a)) {
         echo "The judgment result is empty"
      }
     //isset ($a) returns true
      if (isset ($a)) {
         echo "The judgment result is not empty"
      }
    ?>
php
  • Previous New API for iOS9-Spotlight Guide
  • Next Definition of apply and call methods and the difference between apply and call methods