Created
April 16, 2018 19:56
-
-
Save antoinefortin/9c5da1f6e4d7106d824172374b2925b2 to your computer and use it in GitHub Desktop.
[Reccursive Loop PHP]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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