Skip to content

Instantly share code, notes, and snippets.

@Willshaw
Last active December 17, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Willshaw/5642619 to your computer and use it in GitHub Desktop.
Save Willshaw/5642619 to your computer and use it in GitHub Desktop.
PHP Fibonacci number
<?
// array to store sequence - initialised with first 2 numbers
$nums = array(0,1);
// loop 20 times creating more numbers in the sequence
for($i = 1; $i <=20; $i++) {
$next = $nums[$i]+$nums[$i-1];
array_push($nums,$next);
}
// output sequence, one number per new line
foreach ($nums as $num => $val) {
echo '<br />'.$val;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment