Bird
0
0

Why does the strict equality operator (===) in PHP return false when comparing 0 and '0'?

hard📝 Conceptual Q10 of 15
PHP - Operators
Why does the strict equality operator (===) in PHP return false when comparing 0 and '0'?
ABecause their values are different
BBecause their types are different
CBecause PHP does not allow string and integer comparison
DBecause === only compares memory addresses
Step-by-Step Solution
Solution:
  1. Step 1: Understand strict equality operator behavior

    === compares both value and type without converting types.
  2. Step 2: Compare 0 (integer) and '0' (string)

    Values are equal but types differ (integer vs string), so === returns false.
  3. Final Answer:

    Because their types are different -> Option B
  4. Quick Check:

    Strict equality requires same type and value [OK]
Quick Trick: === returns false if types differ even if values match [OK]
Common Mistakes:
  • Thinking values differ
  • Believing PHP forbids string-int comparison
  • Confusing === with pointer comparison

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes