This is a basic PHP program which describes how to write a Fibonacci series program in PHP. Below examples will help you in the better understanding of the Fibonacci series concept in PHP programming language.
We are using for loop and series()
function to find the Fibonacci series of entered number. Copy the below code and execute it with the help of PHP compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<html> <head> <title>Fibonacci series using recursive function in PHP</title> </head> <body> <form method="post"> Enter a Number: <input type="text" name="number"> <input type="submit" value="Submit"> </form> </body> </html> <?php /** * Fibonacci series using recursive function in PHP */ if($_POST) { $num = $_POST['number']; echo "<h3>Fibonacci series using recursive function:</h3>"; echo "\n"; /* Recursive function for fibonacci series. */ function series($num){ if($num == 0){ return 0; }else if( $num == 1){ return 1; } else { return (series($num-1) + series($num-2)); } } /* Call Function. */ for ($i = 0; $i < $num; $i++){ echo series($i); echo "\n"; } } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.