Last active
February 20, 2019 17:55
-
-
Save jimmy89Li/7d5a53a2caef0294b088fc74cce01c6a to your computer and use it in GitHub Desktop.
Fibonacci sequence (0 omitted)
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
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