Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created June 28, 2017 18:45
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 phpfiddle/78a00b232fea50fd921df5f69653c33b to your computer and use it in GitHub Desktop.
Save phpfiddle/78a00b232fea50fd921df5f69653c33b to your computer and use it in GitHub Desktop.
[ Posted by Ellen Bajcar ] funky fibonacci numbers
<!DOCTYPE html>
<html>
<head>
<title>fibonacci Sequence</title>
<link rel="stylesheet" type="text/css" href="common.css" />
<style type="text/css">
th {
text-align: left;
background-color: #aaa;
}
th, td {
padding: 0.2em;
}
tr.alt td {
background: #ddd;
}
table {
margin: 0px;
width: 20em;
border: 1px solid #666;
}
</style>
</head>
<body>
<h2>Fibonacci sequence</h2>
<table>
<tr id="tr1">
<th>Sequence #</th>
<th>Value</th>
</tr>
<tr id="tr2">
<td>F<sub>0</sub></td>
<td>0</td>
</tr>
<tr id="tr3" class="alt">
<td>F<sub>1</sub></td>
<td>1</td>
</tr>
<?php
$iterations = 10;
$num1 = 0;
$num2 = 1;
for ($i=2; $i <= $iterations; $i++ ) {
$sum = $num1 + $num2;
$num1 = $num2;
$num2 = $sum;
?>
<tr <?php if ( $i % 2 != 0 ) echo 'class="alt" ' ?>>
<td>F<sub><?php echo $i ?></sub></td>
<td><?php echo $num2?></td>
</tr>
<?php
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment