Recall & Review
beginner
What is the difference between loose and strict comparison operators in PHP?
Loose comparison (==) checks if values are equal after type juggling. Strict comparison (===) checks if values are equal and of the same type.
Click to reveal answer
beginner
What does the PHP expression (5 == '5') return and why?
It returns true because loose comparison converts the string '5' to the integer 5 before comparing.
Click to reveal answer
beginner
What does the PHP expression (5 === '5') return and why?
It returns false because strict comparison checks both value and type, and here one is integer and the other is string.
Click to reveal answer
intermediate
Which operator should you use to avoid unexpected type coercion in PHP comparisons?
Use the strict comparison operator (===) to avoid unexpected type coercion.
Click to reveal answer
intermediate
What will be the result of (0 == false) and (0 === false) in PHP?
(0 == false) is true because loose comparison converts types. (0 === false) is false because types differ (integer vs boolean).
Click to reveal answer
What does the PHP operator '==' do?
✗ Incorrect
'==' compares values after converting types if needed.
Which operator checks both value and type equality in PHP?
✗ Incorrect
'===' checks if both value and type are the same.
What is the result of ('10' === 10) in PHP?
✗ Incorrect
Strict comparison fails because one is string and the other is integer.
Why is it safer to use '===' instead of '==' in PHP?
✗ Incorrect
'===' avoids bugs caused by automatic type conversion.
What does (null == false) evaluate to in PHP?
✗ Incorrect
null loosely compared to false is false.
Explain the difference between loose and strict comparison operators in PHP with examples.
Think about how PHP treats types when comparing.
You got /4 concepts.
Why is it recommended to use strict comparison (===) in PHP instead of loose comparison (==)?
Consider what happens when different types are compared loosely.
You got /3 concepts.