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
What is session in PHP. How to remove data from a session?
Who is known as the father of php?
What are the different data types in javascript?
What is a static variable in php?
Explain NULL?
What is the purpose of $_ session?
What is the $_ server php_self variable?
Is it possible to use com component in php?
What does the expression exception::__tostring means?
Which method do you follow to get a record from a million records? (Searching not from database, from an array in php)?
What is $_ server request_method == post?
what is the use of include_once in php?
How to delete file in php?
Suppose the variable $var1 is set to 10 and the $var2 is set to the character var1, what's the value of $$var2?
Is salary a ratio or interval?