How to differentiate isset and empty
Answer Posted / amit
isset() will ONLY return true when the value of the variable
is not NULL (and thereby the variable is at least defined).
empty() will return true when the value of the variable is
deemed to be an "empty" value, typically this means 0, "0",
NULL, FALSE and empty string, anything else is not empty.
Some examples
FALSE == isset($foo);
TRUE == empty($foo);
$foo = NULL;
FALSE == isset($foo);
TRUE == empty($foo);
$foo = 0;
TRUE == isset($foo);
TRUE == empty($foo);
$foo = 1;
TRUE == isset($foo);
FALSE == empty($foo);
| Is This Answer Correct ? | 21 Yes | 2 No |
Post New Answer View All Answers
How can a cross-site scripting attack be prevented by php?
What is polymorphism in php?
What is the default session time in php?
Explain the syntax for ‘foreach’ loop with example.
What is the default time in seconds for which session data is considered valid?
Why do you need php?
Is it more secure to use cookies to trfer session ids?
Explain the changes in php versions?
What is strcmp?
Explain include(), include_once, require() and require_once?
Explain scalar type declarations in php7?
Is key exist in array php?
Does php require a web server?
Is laravel frontend or backend?
Does browser understand php?