0
0
PHPprogramming~5 mins

Isset, empty, and is_null behavior in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the isset() function check in PHP?
isset() checks if a variable is set and is not null. It returns true if the variable exists and has a value other than null, otherwise false.
Click to reveal answer
beginner
How does empty() behave with different variable values?
empty() returns true if a variable is not set or its value is considered "empty". This includes 0, "0", "" (empty string), null, false, empty arrays, and unset variables.
Click to reveal answer
intermediate
What is the difference between is_null() and isset()?
is_null() returns true only if the variable's value is exactly null. isset() returns false if the variable is null or not set at all.
Click to reveal answer
beginner
What will empty() return for a variable set to false?
empty() will return true because false is considered an empty value in PHP.
Click to reveal answer
intermediate
If a variable is not declared at all, what will isset() and empty() return?
isset() will return false because the variable does not exist. empty() will return true because the variable is considered empty if not set.
Click to reveal answer
What does isset($var) return if $var = null;?
Atrue
BThrows an error
Cnull
Dfalse
Which of these values will empty() consider as empty?
A1
B"0"
C"Hello"
D42
What does is_null($var) return if $var is not set?
Anull
Bfalse
CThrows a warning
Dtrue
If $var = false;, what does isset($var) return?
Atrue
Bfalse
Cnull
DDepends on PHP version
Which function returns true for an empty array?
Aempty()
Bis_null()
Cisset()
DNone of the above
Explain how isset(), empty(), and is_null() differ in checking variable states in PHP.
Think about what each function considers as 'set' or 'empty'.
You got /5 concepts.
    Describe what happens when you use empty() on a variable that is not declared.
    Consider how empty handles unset variables compared to isset.
    You got /3 concepts.