Skip to content

Instantly share code, notes, and snippets.

@jonataa
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save jonataa/f577ff1ef9612f05d37b to your computer and use it in GitHub Desktop.

Select an option

Save jonataa/f577ff1ef9612f05d37b to your computer and use it in GitHub Desktop.
Fibonacci – Lambda/Closure + Recursive
<?php
$fib = function ($n) use (&$fib) {
if (1 === $n || 2 === $n)
return 1;
return $fib($n - 1) + $fib($n - 2);
};
echo $fib(10); // Output: 55
// Referência: http://www.php.net/manual/en/language.references.pass.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment