Difference Between empty() and isset() In PHP

Hey,



This post is all about difference between empty() and isset().

In PHP empty() and isset() is two in-built function, empty() is used for check whether the variable is empty or null and isset() check whether a variable is defined or not. Here below  I have listed some important information which could gives you idea about the these two functions.

Case -1:

Case-2:

 



Similarly, You can now see isset() and empty() returns true or false in different conditions.

Value of variable ($var)isset($var)empty($var)
“” (an empty string)bool(true)bool(true)
” ” (space)bool(true)bool(false)
FALSEbool(true)bool(true)
TRUEbool(true)bool(false)
array() (an empty array)bool(true)bool(true)
NULLbool(false)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 $var; (a variable declared, but without a value)bool(false)bool(true)