Skip to content

Instantly share code, notes, and snippets.

@rknightuk
Last active December 22, 2015 08:59
Show Gist options
  • Select an option

  • Save rknightuk/6449121 to your computer and use it in GitHub Desktop.

Select an option

Save rknightuk/6449121 to your computer and use it in GitHub Desktop.
Fibonacci sequence
<?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