A PHP function for the Fibonacci sequence
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 |
function fib() { $current = 1; $previous = 0; $evaluation = 0; while($evaluation < 100) { $evaluation = ($current+$previous); $current = $previous; $previous = $evaluation; echo $evaluation . '<br>'; } } |
Leave a Comment