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 escaping to php?

525


How do you remove duplicates from an array?

643


how retrive the video file in php using video tag

1368


What is mysqli_real_escape_string?

520


Explain the different types of errors in php.

518






Why php is used with mysql?

522


What is trim function in php?

604


How to create a session? How to remove data from a session?

510


What is session expiry?

524


Tell me how do I check if a given variable is empty?

526


How to find a substring from a given string in php?

495


Is php a float?

529


What is the use of mysql_real_escape_string in php?

443


What new features php7 has in store for us?

553


Explain type casting and type juggling.

544