PHP isset() vs empty() vs is_null() - Demo
This is a demo page for PHP isset() vs empty() vs is_null()Following is the output that you will see on PHP 8.1.30
Value of variable ($var) | isset($var) | empty($var) | is_null($var) |
---|---|---|---|
"" (an empty string) | bool(true) | bool(true) | bool(false) |
" " (space) | bool(true) | bool(false) | bool(false) |
FALSE | bool(true) | bool(true) | bool(false) |
TRUE | bool(true) | bool(false) | bool(false) |
array() (an empty array) | bool(true) | bool(true) | bool(false) |
NULL | bool(false) | bool(true) | bool(true) |
"0" (0 as a string) | bool(true) | bool(true) | bool(false) |
0 (0 as an integer) | bool(true) | bool(true) | bool(false) |
0.0 (0 as a float) | bool(true) | bool(true) | bool(false) |
var $var; (a variable declared, but without a value) | bool(false) | bool(true) | bool(true) |
NULL byte ("\ 0") | bool(true) | bool(false) | bool(false) |