how to make a loop that adds numbers to a variable in php

Solutions on MaxInterview for how to make a loop that adds numbers to a variable in php by the best coders in the world

showing results for - "how to make a loop that adds numbers to a variable in php"
Alina
11 Oct 2017
1<?php
2
3$start = 1;
4$end = 10;
5
6$sum = 0;
7for ($i = $start; $i <= $end; $i++) {
8    $sum += $i;
9}
10
11echo "Sum from " . $start . " to " . $end . " = " . $sum;
12