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
What is escaping to php?
How do you remove duplicates from an array?
how retrive the video file in php using video tag
What is mysqli_real_escape_string?
Explain the different types of errors in php.
Why php is used with mysql?
What is trim function in php?
How to create a session? How to remove data from a session?
What is session expiry?
Tell me how do I check if a given variable is empty?
How to find a substring from a given string in php?
Is php a float?
What is the use of mysql_real_escape_string in php?
What new features php7 has in store for us?
Explain type casting and type juggling.