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

How can php and javascript interact?

964


Explain what are some new features introduced in php7?

692


What is an anti csrf token?

687


What is cookies php?

715


What is the purpose of $_ session?

700


Do you know what's the difference between __sleep and __wakeup?

759


Binary tree question - Node has numeric data (int) The function takes depth as argument and sum all the value of the node of the depth. For instance, (0) depth 0 / \ 10 20 depth 1 / \ / \ 40 50 60 70 depth 2 so if you pass get_sum(2), you would return 220 which is 40+50+60+70 (sum of depth2) write the function.

1730


What is default session time in php?

718


What are the functions of string?

710


How to get number of elements in an array?

719


What is the php function that removes the first element of the array and returns it?

733


How to create a session? How to set a value in session?

738


How do I know my xampp version?

722


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

758


How can we encrypt the password using php?

757