Bird
0
0

What will this code output?

medium📝 Predict Output Q5 of 15
PHP - Arrays
What will this code output?
$data = [
'x' => [10, 20],
'y' => [30, 40]
];
echo $data['y'][1];
A10
B30
C40
D20
Step-by-Step Solution
Solution:
  1. Step 1: Locate $data['y'] array

    $data['y'] is [30, 40].
  2. Step 2: Access index 1 of $data['y']

    Index 1 is 40.
  3. Final Answer:

    40 -> Option C
  4. Quick Check:

    Access associative key then index = 40 [OK]
Quick Trick: Use key then index to get nested value [OK]
Common Mistakes:
  • Using wrong index 0 instead of 1
  • Mixing keys 'x' and 'y'
  • Assuming output is an array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes