// calculation of : x + (x-1) + ... + 3 + 2 + 1 function sum($x) { if ($x <= 0) return 0; return $x + sum($x-1); } // call it $s = sum(8);