0
0
PHPprogramming~5 mins

Boolean type behavior in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What values are considered true in PHP when converted to boolean?
In PHP, any non-zero number, non-empty string (except "0"), non-empty array, and objects are considered true when converted to boolean.
Click to reveal answer
beginner
Which values are considered false in PHP when converted to boolean?
The following values are considered false: false, integer 0, float 0.0, empty string "", string "0", empty array [], and null.
Click to reveal answer
intermediate
How does PHP treat the string "0" in a boolean context?
The string "0" is treated as false in PHP boolean context, even though it is a non-empty string.
Click to reveal answer
beginner
What happens when you use the boolval() function on different types in PHP?
The boolval() function converts any value to its boolean equivalent following PHP's rules: zero, empty, or null values become false; others become true.
Click to reveal answer
intermediate
Explain the difference between == and === when comparing booleans in PHP.
The == operator compares values after type juggling, so 0 == false is true. The === operator compares both value and type, so 0 === false is false.
Click to reveal answer
Which of these values is considered false in PHP boolean context?
A"false" (string)
B1 (integer one)
C"0" (string zero)
D[1, 2, 3] (non-empty array)
What does boolval(0.0) return in PHP?
Afalse
Bnull
Ctrue
D0
Which operator checks both value and type in PHP?
A==
B||
C!=
D===
What is the boolean value of an empty array [] in PHP?
Atrue
Bfalse
Cnull
DDepends on context
Which of these is NOT considered false in PHP?
A"false" (string)
B"" (empty string)
C0
Dnull
Describe which values PHP treats as false in boolean context and why this might be surprising.
Think about zero, empty, and null values.
You got /3 concepts.
    Explain the difference between == and === when comparing booleans in PHP with examples.
    Focus on type comparison.
    You got /4 concepts.