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?
✗ Incorrect
The string "0" is considered false in PHP boolean context, while the others are true.
What does
boolval(0.0) return in PHP?✗ Incorrect
0.0 is treated as false when converted to boolean.
Which operator checks both value and type in PHP?
✗ Incorrect
The === operator checks both value and type equality.
What is the boolean value of an empty array
[] in PHP?✗ Incorrect
An empty array is considered false in boolean context.
Which of these is NOT considered false in PHP?
✗ Incorrect
The string "false" is a non-empty string and is considered true.
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.