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

Is apache needed for php?

696


How many types of php frameworks are there?

699


What is the importance of php?

736


Tell me can the value of a constant change during the script's execution?

914


What kind of things have you done on the social side?

8800


What is split function in php?

728


Does strlen include null?

819


Explain preg_Match and preg_replace?

769


What does csrf token mismatch mean?

920


What are objects in php?

731


Why php is also called as scripting language?

744


What is a simple php method to make a cross domain data request?

726


How is it possible to know the number of rows returned in the result set?

804


Where to put php files in apache server?

737


How values in arrays are indexed?

808