Recall & Review
beginner
What is loose comparison in PHP?
Loose comparison uses the == operator and compares values after converting them to a common type. It checks if values are equal but ignores their data types.
Click to reveal answer
beginner
What is strict comparison in PHP?
Strict comparison uses the === operator and compares both the value and the data type. Both must be exactly the same for the comparison to be true.
Click to reveal answer
intermediate
What will be the result of: 0 == '0' and 0 === '0' in PHP?
0 == '0' is true because loose comparison converts '0' to integer 0.<br>0 === '0' is false because strict comparison checks type and integer is not string.
Click to reveal answer
intermediate
Why can loose comparison lead to unexpected results?
Because it converts types automatically, values that look different can be treated as equal, which may cause bugs if you expect exact matches.
Click to reveal answer
beginner
When should you use strict comparison over loose comparison?
Use strict comparison when you want to be sure both value and type match exactly, such as checking user input or sensitive data.
Click to reveal answer
Which operator in PHP performs strict comparison?
✗ Incorrect
The === operator checks both value and type, making it a strict comparison.
What does loose comparison do before comparing values?
✗ Incorrect
Loose comparison converts values to a common type before comparing.
What is the result of '5' == 5 in PHP?
✗ Incorrect
Loose comparison converts '5' to integer 5, so they are equal.
What is the result of '5' === 5 in PHP?
✗ Incorrect
Strict comparison checks type, string is not integer, so false.
Which comparison is safer to avoid unexpected bugs?
✗ Incorrect
Strict comparison avoids type juggling and unexpected matches.
Explain the difference between loose and strict comparison in PHP.
Think about how PHP treats types in each comparison.
You got /4 concepts.
Give an example where loose comparison can cause a bug and how strict comparison fixes it.
Consider comparing a number and a string.
You got /4 concepts.