Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Type Handling
What will be the output of the following PHP code?
$a = 0;
var_dump(isset($a));
var_dump(empty($a));
var_dump(is_null($a));
Abool(true)<br>bool(false)<br>bool(false)
Bbool(false)<br>bool(true)<br>bool(true)
Cbool(false)<br>bool(false)<br>bool(true)
Dbool(true)<br>bool(true)<br>bool(false)
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate isset($a) when $a = 0

    $a is set and not null, so isset($a) returns true.
  2. Step 2: Evaluate empty($a) when $a = 0

    Zero is considered empty in PHP, so empty($a) returns true.
  3. Step 3: Evaluate is_null($a) when $a = 0

    $a is integer zero, not null, so is_null($a) returns false.
  4. Final Answer:

    bool(true)
    bool(true)
    bool(false)
    -> Option D
  5. Quick Check:

    isset true, empty true for 0, is_null false [OK]
Quick Trick: 0 is set and empty, but not null [OK]
Common Mistakes:
  • Thinking isset returns false for 0
  • Confusing empty with is_null
  • Assuming 0 is null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes