isset()
, empty()
and is_null()
functions; and the differences in responses.
Value of Variable | isset() |
empty() |
is_null() |
---|---|---|---|
"" (an empty string) | bool(true) | bool(true) | |
" " (space) | bool(true) | ||
FALSE | bool(true) | bool(true) | |
TRUE | bool(true) | ||
array() (an empty array) | bool(true) | bool(true) | |
NULL | bool(true) | bool(true) | |
"0" (0 as a string) | bool(true) | bool(true) | |
0 (0 as an integer) | bool(true) | bool(true) | |
0.0 (0 as a float) | bool(true) | bool(true) | |
var ; (a variable declared, but without a value) | bool(true) | bool(true) | |
NULL byte ("") | bool(true) |
This page has been created as I kept losing where I found this on the internet. It covers certain PHP functions that have interesting functionality.
It's originally from https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ so thanks to them for that page! Super useful.