The usage of PHP empty (), isset (), and is_null () functions has been discussed a lot, and many materials may not be clear. I will repeat it again here, but I should remember it more deeply, instead of simply using program examples to speak.
The test type is as follows:
Copy codeThe Code is as follows:
<? Php
$;
$ B = false;
$ C = '';
$ D = 0;
$ E = null;
$ F = array ();
?>
Empty ()
The first is the var_dump output of empty:
Copy codeThe Code is as follows:
<? Php
Var_dump (empty ($ ));
Var_dump (empty ($ B ));
Var_dump (empty ($ c ));
Var_dump (empty ($ d ));
Var_dump (empty ($ e ));
Var_dump (empty ($ f ));
?>
Program output:
Bool (true)
Bool (true)
Bool (true)
Bool (true)
Bool (true)
Bool (true)
The Code shows that empty () Outputs true if the data type is null or false.
Isset ()
Let's take a look at the output of isset:
Var_dump (isset ($ ));
Var_dump (isset ($ B ));
Var_dump (isset ($ c ));
Var_dump (isset ($ d ));
Var_dump (isset ($ e ));
Var_dump (isset ($ f ));
// Output
Bool (false)
Bool (true)
Bool (true)
Bool (true)
Bool (false)
Bool (true)
We can see that isset () can only be used to determine whether it is NULL or not.
Is_null ()
Finally, the output of is_null is as follows:
Var_dump (is_null ($ ));
Var_dump (is_null ($ B ));
Var_dump (is_null ($ c ));
Var_dump (is_null ($ d ));
Var_dump (is_null ($ e ));
Var_dump (is_null ($ f ));
// Output
Bool (true)
Bool (false)
Bool (false)
Bool (false)
Bool (true)
Bool (false)
Is_null.
It can be seen that empty () can be used to determine whether all data types are NULL or false, while is_null is basically the same as isset and can only be used to determine whether it is NULL or undefined.