Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Type Handling
What will be the output of this PHP code?
$arr = ['a' => 0, 'b' => null];
echo empty($arr['a']) ? 'Empty' : 'Not Empty';
ANot Empty
Bnull
CError
DEmpty
Step-by-Step Solution
Solution:
  1. Step 1: Check value of $arr['a']

    $arr['a'] is 0, which empty() treats as empty.
  2. Step 2: Evaluate empty() result

    empty(0) returns true, so ternary outputs 'Empty'.
  3. Final Answer:

    Empty -> Option D
  4. Quick Check:

    empty(0) = true [OK]
Quick Trick: empty() treats 0 as empty [OK]
Common Mistakes:
  • Expecting 'Not Empty' for 0
  • Confusing empty() with isset()
  • Thinking null affects this key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes