Not much nonsense to say, directly to everyone put the code.
<?php class test{} $a 1 = null; $a 2 = ""; $a 3 = $a 4 = 0; $a 5 = ' 0 '; $a 6 = false; $a 7 = array (); var $a 8; $a 9 = 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 '
'; }
The difference between empty () and Isset () in ps:php
For beginners of PHP, the difference between empty () and isset () usage is hard to figure out, and it's hard to figure out the difference in their usage without careful thought.
Let's talk about what they have in common:
Can determine whether a variable is empty;
Returns a Boolean type, which is either true or false.
Here's a specific distinction between their usage:
Isset () is used to detect if a variable is set and can only be used for variables, because passing any other parameter will result in parsing errors. To detect if a constant is set, use the defined () function. If a variable has been freed with unset (), 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 ("s") is not equivalent to a null constant in PHP)
Empty () is used to check if a variable is empty.
The biggest difference between them is the judgment of 0, if it is judged empty by empty, with isset it is not empty, for example:
<?php var $a =0; Empty ($a) returns True if (empty ($a)) { echo "judgment result is empty" } //isset ($a) returns True if (isset ($a)) { echo " Judgment result is not empty " } ?>