Created
May 16, 2011 06:04
-
-
Save hnw/973995 to your computer and use it in GitHub Desktop.
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 fib ($n) { | |
$fib_internal = function ($n, $cur, $prev) use (&$fib_internal) { | |
if ($n === 0) { return $cur; } | |
return $fib_internal($n - 1, $cur + $prev, $cur); | |
}; | |
return $fib_internal($n, 0, 1); | |
} | |
var_dump(fib(6)); // int(8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment