Skip to content

Instantly share code, notes, and snippets.

@AJ-Acevedo
Created December 11, 2012 17:38
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 AJ-Acevedo/4260530 to your computer and use it in GitHub Desktop.
Save AJ-Acevedo/4260530 to your computer and use it in GitHub Desktop.
Fibonacci Sequence using PHP
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>Fibonacci Sequence using PHP</title>
</head>
<body>
<div align=center>
<h1>Fibonacci Sequence using PHP</h1>
</div>
<br>
<div id="fib">
<?php
$a = 0;
$b = 1;
$c = $a + $b;
//echo the first 0, 1 of the sequence
echo $a . ", " . $b . ", ";
while ($c <= 4181) {
// if statement that adds ... instead of a , once the end of the sequence is reached.
echo "$c" . ( ($c == 4181) ? "..." : ", ");
$a = $b;
$b = $c;
$c = $a + $b;
}
?>
</div>
<p><br>
<p><?php echo '-------------------------------------------------------------------------------------------';?></p>
<p><a href="http://en.wikipedia.org/wiki/Fibonacci_number" title="Fibonacci Sequence on wikipedia">Fibonacci Sequence on wikipedia</a></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment