I was recently asked as a test to write a function that outputs the Fibonacci sequence in PHP. Here it is:
1
2
3
4
5
6
7
8
9
10
11
12
|
<?php
function fib() {
$current = 1;
$previous = 0;
$evaluation = 0;
while($evaluation < 100) {
$evaluation = ($current+$previous);
$current = $previous;
$previous = $evaluation;
echo $evaluation . '<br>';
}
}
echo fib();
?>
|
0 comments:
Post a Comment