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 can php and javascript interact?
Explain what are some new features introduced in php7?
What is an anti csrf token?
What is cookies php?
What is the purpose of $_ session?
Do you know what's the difference between __sleep and __wakeup?
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.
What is default session time in php?
What are the functions of string?
How to get number of elements in an array?
What is the php function that removes the first element of the array and returns it?
How to create a session? How to set a value in session?
How do I know my xampp version?
Which method do you follow to get a record from a million records? (Searching not from database, from an array in php)?
How can we encrypt the password using php?