Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Loops
What will be the output of this PHP code?
$total = 0;
for ($i = 1; $i <= 5; $i++) {
  $total += $i;
}
echo $total;
A15
B10
C5
D0
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop

    The loop runs from 1 to 5, adding each number to $total.
  2. Step 2: Calculate sum

    1 + 2 + 3 + 4 + 5 = 15
  3. Final Answer:

    15 -> Option A
  4. Quick Check:

    Sum of 1 to 5 is 15 [OK]
Quick Trick: Sum numbers 1 to 5 = 15 [OK]
Common Mistakes:
  • Adding only up to 4
  • Misunderstanding loop boundaries
  • Ignoring increment in loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes