Page 109 - Beginning PHP 5.3
P. 109
Chapter 4: Decisions and Loops
< ?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
}
? >
< /table >
< /body >
< /html >
Try saving this file as fibonacci.php in your document root folder and running the script in your
browser. Figure 4 - 5 shows the result.
Figure 4-5
71
9/21/09 8:52:13 AM
c04.indd 71
c04.indd 71 9/21/09 8:52:13 AM