This article describes how to judge the parameter structure of empty and isset in PHP and the differences between empty () and isset (). If you need more information, refer to the following, paste the Code directly.
<?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 '
'; } echo '
'; for ($i=1; $i <=9 ; $i++) { $s = 'a'.$i; echo $i . ":"; var_dump(empty($$s)); echo '
'; }
PS: differences between empty () and isset () in PHP
For beginners of php, the difference between empty () and isset () is difficult to figure out. It is really difficult to figure out the difference between their usage without careful consideration.
Let's talk about what they have in common:
You can determine whether a variable is null;
Return the boolean type, that is, true or false.
The differences between their usage are as follows:
Isset () is used to check whether a variable is set. It can only be used for a variable because passing any other parameter will cause a parsing error. To check whether a constant has been set, use the defined () function. If unset () is used to release a variable, it will no longer be isset (). If you use isset () to test a variable that is set to NULL, FALSE is returned. (Note that a NULL byte ("\ 0") is not equivalent to the NULL constant of PHP)
Empty () is used to check whether a variable is empty.
The biggest difference between them is the determination of 0. If empty is used, it is considered to be null. If isset is used, it is considered not null. For example:
<? Php var $ a = 0; // empty ($ a) returns true if (empty ($ a) {echo "The result is null"} // isset ($) returns true if (isset ($ a) {echo "the result is not empty"}?>