Skip to content

Instantly share code, notes, and snippets.

@hnw
Created May 16, 2011 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnw/973995 to your computer and use it in GitHub Desktop.
Save hnw/973995 to your computer and use it in GitHub Desktop.
<?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