Created
March 10, 2016 19:24
-
-
Save ggirtsou/9d1897ca9cc4d96b8bfd to your computer and use it in GitHub Desktop.
Prints fibonacci sequence based on $numbersToShow starting from $startNumber
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
<?php | |
error_reporting(E_ALL); | |
ini_set('display_errors', true); | |
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 | |
$startNumber = 0; | |
$numbersToShow = 10; | |
function fibonacci($number) | |
{ | |
if ($number === 0) { | |
return 0; | |
} elseif ($number === 1) { | |
return 1; | |
} else { | |
return (fibonacci($number-1) + fibonacci($number-2)); | |
} | |
} | |
for ($i = $startNumber; $i < ($startNumber+$numbersToShow); $i++) { | |
echo fibonacci($i).PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment