This article provides a detailed analysis of PHPempty (), isset (), and is_null () instance tests. For more information, see empty () and isset () of PHP () the usage of the three functions is_null () 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:
<?php$a;$b = false;$c = '';$d = 0;$e = null;$f = array();?>
Empty ()
The first is the var_dump output of empty:
<?phpvar_dump(empty($a));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 ($ a); 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 (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 ($ a); 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 (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.