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


Please Help Members By Posting Answers For Below Questions

What is session in PHP. How to remove data from a session?

517


Who is known as the father of php?

562


What are the different data types in javascript?

521


What is a static variable in php?

535


Explain NULL?

579






What is the purpose of $_ session?

519


What is the $_ server php_self variable?

494


Is it possible to use com component in php?

556


What does the expression exception::__tostring means?

562


Which method do you follow to get a record from a million records? (Searching not from database, from an array in php)?

550


What is $_ server request_method == post?

540


what is the use of include_once in php?

538


How to delete file in php?

527


Suppose the variable $var1 is set to 10 and the $var2 is set to the character var1, what's the value of $$var2?

544


Is salary a ratio or interval?

556