Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - Arrays
What will be the output of the following PHP code?
$arr = [1, 2, 3];
$arr[1] = 10;
echo $arr[1];
A2
B3
C1
D10
Step-by-Step Solution
Solution:
  1. Step 1: Understand array modification

    The code changes the element at index 1 from 2 to 10.
  2. Step 2: Identify the echoed value

    After modification, $arr[1] is 10, so echo outputs 10.
  3. Final Answer:

    10 -> Option D
  4. Quick Check:

    Modified element output = 10 [OK]
Quick Trick: Array index assignment changes value immediately [OK]
Common Mistakes:
  • Assuming original value remains unchanged
  • Confusing index positions
  • Expecting output of entire array instead of single element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes