Skip to content

Instantly share code, notes, and snippets.

@jimmy89Li
Last active February 20, 2019 17:55
Show Gist options
  • Save jimmy89Li/7d5a53a2caef0294b088fc74cce01c6a to your computer and use it in GitHub Desktop.
Save jimmy89Li/7d5a53a2caef0294b088fc74cce01c6a to your computer and use it in GitHub Desktop.
Fibonacci sequence (0 omitted)
function fibonacci($n)
{
//$fib = [0,1] // use this if you don't want to omit '0'
$fib = [1,1];
for($i=1;$i<$n;$i++)
{
$fib[] = $fib[$i]+$fib[$i-1];
}
//print_r($fib);
echo $fib[$n];
}
fibonacci(4); // = 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment