sum of number 1 to n
<?php

$x = 10;

// Sum of numbers from 1 to n
$sum = 0;
for ($i = 1;  $i <= $x;  $i++) {
	$sum += $i;
}
echo "SUM of numbers from 1 to $x: $sum\n";


// easy way to calculate SUM of numbers to n
$sum = $from1To * ($x+1) / 2;
echo "SUM of numbers from 1 to $x: $sum\n";
by Gvanca Gharibashvili
2 years ago
PHP
Object Oriented PHP Tutorial
0
Pro tip: use ```triple backticks around text``` to write in code fences