Skip to content

Instantly share code, notes, and snippets.

@antoinefortin
Created April 16, 2018 19:56
Show Gist options
  • Save antoinefortin/9c5da1f6e4d7106d824172374b2925b2 to your computer and use it in GitHub Desktop.
Save antoinefortin/9c5da1f6e4d7106d824172374b2925b2 to your computer and use it in GitHub Desktop.
[Reccursive Loop PHP]
<?php
function sum($arr, $n) {
static $staticSum = 0;
if ($n == 0) {
$theSum = $staticSum;
return $theSum;
}
$n--;
$staticSum += $arr[$n];
sum($arr, $n);
}
$var= array();
$var = [1, 2, 3, 4, 56];
$sum = sum($var, 5);
//var_dump($sum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment