Skip to content

Instantly share code, notes, and snippets.

@flangofas
Created August 3, 2014 20:21
Show Gist options
  • Save flangofas/3fc78963f30adc3f8d3e to your computer and use it in GitHub Desktop.
Save flangofas/3fc78963f30adc3f8d3e to your computer and use it in GitHub Desktop.
Fibonacci sequence
<?php
echo fibonacciCode($argv[1]) . PHP_EOL;
/**
* This function returns the fibonacci sequence
*
* @param mixed sequence
* @return int total
*/
function fibonacciCode($sequence = 0) {
$total = 0;
$i = 0;
$a = 0;
$b = 1;
while ($i < $sequence) {
$total = $a + $b;
$i++;
$a = $b;
$b = $total;
}
return (int)$total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment