Bird
0
0

You wrote this PHP code:

medium📝 Debug Q14 of 15
PHP - Request Lifecycle
You wrote this PHP code:
<?php
$sum = 10;
$sum += 5;
?>

But after refreshing the page, $sum is always 15. You want $sum to keep increasing by 5 each time the page loads. What is the problem?
AYou need to use a loop to increase $sum
BThe += operator does not add values correctly
CYou forgot to declare $sum as global
DPHP resets variables after each script run, so $sum starts at 10 every time
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable reset behavior

    PHP clears all variables after each script finishes, so $sum resets to 10 every time.
  2. Step 2: Why $sum does not keep increasing

    Because $sum is reinitialized to 10 on each page load, adding 5 results in 15 always.
  3. Final Answer:

    PHP resets variables after each script run, so $sum starts at 10 every time -> Option D
  4. Quick Check:

    Variables reset each run = D [OK]
Quick Trick: Variables reset each run; use sessions or files to keep values [OK]
Common Mistakes:
  • Thinking += operator is faulty
  • Assuming global declaration keeps value between runs
  • Believing loops affect variable persistence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes