Skip to content

Instantly share code, notes, and snippets.

@marcmascort
Created September 6, 2014 00:23
Show Gist options
  • Save marcmascort/9ed0822d6215eb6877c9 to your computer and use it in GitHub Desktop.
Save marcmascort/9ed0822d6215eb6877c9 to your computer and use it in GitHub Desktop.
Get the Fibonacci sequence
<?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