Resolve empty is_null and isset tests in PHP
- 2020-06-23 00:02:34
- OfStack
The code is as follows:
<?php
$a;
$b = false;
$c = '';
$d = 0;
$e = null;
$f = array();
The first is the var_dump output of empty:
boolean true
boolean true
boolean true
boolean true
boolean true
boolean true
Then the output of is_null:
boolean true
boolean false
boolean false
boolean false
boolean true
boolean false
Finally, the output of isset:
boolean false
boolean true
boolean true
boolean true
boolean false
boolean true
Thus, empty() can be used to determine whether all data types are null or false, while is_null, like isset, can only be used to determine whether it is NULL and undefined.