source code in php for fibonacci sequence

Solutions on MaxInterview for source code in php for fibonacci sequence by the best coders in the world

showing results for - "source code in php for fibonacci sequence"
Braden
27 Nov 2020
1 
2<?php
3// PHP code to get the Fibonacci series  Recursive function for fibonacci series. 
4function Fibonacci($number){ 
5      
6 
7    if ($number == 0) 
8        return 0;     
9    else if ($number == 1) 
10        return 1;     
11      
12    else
13        return (Fibonacci($number-1) +  
14                Fibonacci($number-2)); 
15} 
16?>
17<!doctype html>
18<html>
19<head>
20<meta charset="utf-8">
21<title>Code 4 Example - PHP Examples</title>
22</head>
23 
24<body>
25<form action="" method="post">
26	Number:<input type="text" name="number" value="<?=$_POST['number']??''?>"><br>
27	<input type="submit" name="print" value="Print Fibonacci Numbers">
28</form>	
29<?php   
30 
31if(isset($_POST["print"]))
32{
33	$number = $_POST["number"]; 
34	for ($counter = 0; $counter < $number; $counter++){   
35		echo '<strong>'.Fibonacci($counter).'</strong> '; 
36	} 	
37}
38?>
39</body>
40</html>
41 
42