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
How to delete a file from the system?
When to use inquire vs enquire?
How is it possible to return a value from a function?
What are the different data types in javascript?
What is a php form?
What are php applications?
What is needed to be able to use image function?
Explain how is it possible to cast types in php?
How to upload file in php?
Write an example to remove html tags from a string in php?
How to track user logged out or not? When user is idle?
Write a program to display reverse of any number?
Why is php used?
What's the difference between using mysql_ functions and pdo?
What is the goto statement useful for?