Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Conditional Statements
What will be the output of this PHP code?
$x = 0;
echo $x ?? 10;
A10
B0
Cnull
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand null coalescing with zero value

    The variable $x is set and equals 0, which is not null.
  2. Step 2: Evaluate the expression

    Since $x is not null, $x ?? 10 returns 0.
  3. Final Answer:

    0 -> Option B
  4. Quick Check:

    Null coalescing checks for null, not falsy values [OK]
Quick Trick: Null coalescing treats 0 as valid, not null [OK]
Common Mistakes:
  • Confusing null with falsy zero
  • Expecting default value for 0
  • Thinking it causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes