Bird
0
0

You have an array $data = ['x' => 0, 'y' => null, 'z' => '']. Which keys will isset() return true for?

hard📝 Application Q8 of 15
PHP - Type Handling
You have an array $data = ['x' => 0, 'y' => null, 'z' => '']. Which keys will isset() return true for?
A'x' only
B'x' and 'z'
C'x' and 'y'
DAll keys
Step-by-Step Solution
Solution:
  1. Step 1: Check isset() on each key

    isset() returns false if value is null or variable not set.
  2. Step 2: Evaluate each key

    'x' = 0 (set, not null) true, 'y' = null false, 'z' = '' (empty string but set) true.
  3. Step 3: Verify isset() on empty string

    isset('') returns true because variable is set and not null.
  4. Final Answer:

    'x' and 'z' -> Option B
  5. Quick Check:

    isset('') = true, isset(null) = false [OK]
Quick Trick: isset() true for set and not null values [OK]
Common Mistakes:
  • Thinking isset() false for empty string
  • Confusing null and empty string
  • Assuming isset() false for 0

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes