Created
September 6, 2014 00:23
-
-
Save marcmascort/9ed0822d6215eb6877c9 to your computer and use it in GitHub Desktop.
Get the Fibonacci sequence
This file contains 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 fibonacci_sequence($limit=0) | |
{ | |
$limit = abs(intval($limit)); | |
$sequence = array(); | |
$count = 0; | |
while($count < $limit) | |
{ | |
$a = isset($sequence[$count-2]) ? $sequence[$count-2] : 0; | |
$b = isset($sequence[$count-1]) ? $sequence[$count-1] : 1; | |
$sequence[] = $a + $b; | |
++$count; | |
} | |
return $sequence; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment