I am learning PHP. Can someone help me understand how to sum numbers?
For example, I want to use a for loop to sum all numbers from 1 to 10:
'1+2+3+4+5+6+7+8+9+10=?'
I am learning PHP. Can someone help me understand how to sum numbers?
For example, I want to use a for loop to sum all numbers from 1 to 10:
'1+2+3+4+5+6+7+8+9+10=?'
Since you specifically said for loop:
<?php
$start = 1;
$end = 10;
$sum = 0;
for ($i = $start; $i <= $end; $i++) {
$sum += $i;
}
echo "Sum from " . $start . " to " . $end . " = " . $sum;