Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Arrays
What will be the output of the following PHP code?
$arr = [5, 10, 15];
$arr[1] = $arr[1] + 5;
echo $arr[1];
A15
B10
C20
D5
Step-by-Step Solution
Solution:
  1. Step 1: Understand initial array values

    $arr = [5, 10, 15]; so $arr[1] is 10.
  2. Step 2: Calculate new value of $arr[1]

    $arr[1] = $arr[1] + 5 means 10 + 5 = 15.
  3. Final Answer:

    15 -> Option A
  4. Quick Check:

    10 + 5 = 15 [OK]
Quick Trick: Add to existing value using $arr[index] + number [OK]
Common Mistakes:
  • Printing old value without update
  • Adding index instead of value
  • Confusing array indexes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes