Last active
December 22, 2015 08:59
-
-
Save rknightuk/6449121 to your computer and use it in GitHub Desktop.
Fibonacci sequence
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 | |
| $number = 8; // Index of fibonacci number | |
| if ($number < 3) { | |
| $answer = 1; | |
| echo "Answer: " . $answer; | |
| } | |
| else { | |
| $num1 = 1; | |
| $num2 = 1; | |
| $count = 2; | |
| while ($count != $number) { | |
| $answer = $num1 + $num2; | |
| $num1 = $num2; | |
| $num2 = $answer; | |
| $count ++; | |
| } | |
| echo "Answer: " . $answer . "</br>"; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment