What is the difference between !isset
and empty
, isset
and !empty
??
Definition and Usage The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL. This function returns true if the variable exists and is not NULL, otherwise it returns false.
A variable is NULL if it has no value, and points to nowhere in memory. empty() is more a literal meaning of empty, e.g. the string "" is empty, but is not NULL .
empty() function in PHP ? The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases.
PHP empty() FunctionThe empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.
The type comparison tables should answer all questions about these operators: http://php.net/manual/en/types.comparisons.php
The basic answer would be that a variable can be set (not NULL) and yet be empty(can be assimilated to 0). Consider an empty array for example.
From the link presented by @mjhennig, you can see that 0 is considered to be empty. So is False and the empty string(obviously) :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With