How to differentiate isset and empty

Answers were Sorted based on User's Feedback



How to differentiate isset and empty ..

Answer / p .g .senthilkumar

isset -> this variable handling functions determine whether
a variable is set . It checks whether a variable is set
even though it is empty.

empty -> as the term itself has already given a sign that
it would related to something that's empty, this variable
handling functions determine whether a variable is empty.
It checks whether a variable has a value whether it's empty
string, zero(0), or not set at all.

Is This Answer Correct ?    36 Yes 1 No

How to differentiate isset and empty ..

Answer / 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

How to differentiate isset and empty ..

Answer / rahul shelar

isset is used for checking whether variable is set or not
and empty checks whether it is empty

Is This Answer Correct ?    19 Yes 5 No

How to differentiate isset and empty ..

Answer / vijay

isset is used to check whether the variable is set or
not ...
where as empty is used to check whether variable contains a
value or not

Is This Answer Correct ?    12 Yes 1 No

How to differentiate isset and empty ..

Answer / techytech

0, "0",
NULL, FALSE and empty string,

for this value empty() will return TRUE

Is This Answer Correct ?    3 Yes 0 No

How to differentiate isset and empty ..

Answer / rafique

actually, !isset and empty are one and same thing...

Is This Answer Correct ?    2 Yes 31 No

Post New Answer

More PHP Interview Questions

Do you know how to delete a file from the system?

0 Answers  


What is composer install?

0 Answers  


how to retrieve from database..... this format (PRMRMDU402). firstname= prabhu, lastname=kumar, city=madurai, pincode=624402.... i want first name first two letters and last name last two letters ... city first two letters ... pin code last three letters....

2 Answers  


What are the encryption techniques in php?

0 Answers  


What is the difference between the functions unlink and unset?

8 Answers   Small Firm, TCS,






What is the use of "echo" in php?

0 Answers  


Tell me what types of loops exist in php?

0 Answers  


Explain object-oriented methodology in php?

0 Answers  


How to repeat a string to a specific number of times in php?

0 Answers  


How do you call a constructor for a parent class?

0 Answers  


What are the differences between PHP3 and PHP4 and PHP5? what is the current stable version of PHP?

0 Answers  


Tell me how can you pass a variable by reference?

0 Answers  


Categories