Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q13 of 15
PHP - Operators
What will be the output of this PHP code?
$a = 0;
$b = '0';
var_dump($a == $b);
var_dump($a === $b);
Abool(true) bool(false)
Bbool(false) bool(true)
Cbool(true) bool(true)
Dbool(false) bool(false)
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate loose comparison ($a == $b)

    0 (int) and '0' (string) are equal after type conversion, so $a == $b is true.
  2. Step 2: Evaluate strict comparison ($a === $b)

    Types differ (int vs string), so $a === $b is false.
  3. Final Answer:

    bool(true) bool(false) -> Option A
  4. Quick Check:

    Loose == true, Strict === false [OK]
Quick Trick: Remember === checks type too, == converts types [OK]
Common Mistakes:
  • Assuming both comparisons return true
  • Ignoring type difference in strict check
  • Confusing output order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes