28.02.2019, 19:11
I have this simple for loop:
Which outputs:
Now what I want is to add all the previous numbers on each loop. So the output should be:
I tried this:
But this is the output I get:
How can I get the desired results?
Код:
for($i = 1; $i <= 7; $i++) { echo $i . "<br>"; }
Код:
1 2 3 4 5 6 7
Код:
1 2 // current number + all above 3 // current number + all above 6 // current number + all above 12 // current number + all above 24 // current number + all above 48 // current number + all above
Код:
$sum = 0; for($i = 1; $i <= 7; $i++) { $sum = $sum + $i; echo $sum . "<br>"; }
Код:
1 3 6 10 15 21 28