Skip to content

How to make a loop that adds numbers to a variable in PHP?

<?php

$start = 1;
$end = 10;

$sum = 0;
for ($i = $start; $i <= $end; $i++) {
    $sum += $i;
}

echo "Sum from " . $start . " to " . $end . " = " . $sum;
See also  Python code snippet - How to update a package?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.