Fibonacci Series is a series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 etc.
As seems that, the first two numbers in this sequence are either 1 and 1 or 0 and 1 depending on the chosen starting point of the sequence and each subsequent number is the sum of the previous two.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation:
Fn = Fn-1 + Fn-2
with seed values
F0 = 0 and F1 = 1.
If you want to print the fibonacci number for 10th then it will be 55.
Code for PHP:
<?php
function fib($n)
{
if ($n <= 1)
return $n;
return fib($n – 1) +
fib($n – 2);
}
$n = 10;
echo fib($n);
?>
Output: 55
In case, if you want to print the whole Fibonacci series in PHP then the code is:
You may also like:<?php
$numbers=array(1, 1);
for($i=1;$numbers[$i]<=2000;$i++)
{
$numbers[]=$numbers[$i]+$numbers[$i-1];
}
echo “<p><pre>”;
print_r($numbers);
echo “</pre></p>”;
for($j=0;isset($numbers[$j]);$j++)
{
echo “<p>ID: “.$j.”<br />Value: “.$numbers[$j].”</p>”;
}
?>
- Most Common DNS Record Types and Their Roles
- Top Skills Needed to Become a Cybersecurity Analyst
- Mastering Windows Management with WMIC Commands – Top 20 Examples
- Edit and Compile Code with the Best 5 Code Editors
- 50+ Top DevSecOps Tools You Need To Know
- Learn How to Add Proxy and Multiple Accounts in MoreLogin
- Some Useful PowerShell Cmdlets
- Create Free SSL Certificate – ZEROSSL.COM [2020 Tutorial]
- Generate Self-Signed SSL Certificate with OPENSSL in Kali Linux
- RDP – CredSSP Encryption Oracle Remediation Solution 2020