Simple Writing Method of Fibonacci Sequence Realized by php
- 2021-07-09 07:46:17
- OfStack
Fibonacci sequence is a very common class 1 sequence, which is mathematically defined as F0=1, F1=1, Fn=F (n-1) + F (n-2) (n > = 2, n ε N*). In this paper, php is used to simply realize Fibonacci sequence, and the code 10 points is simple and easy to understand, as follows:
<?php
$arr[1] = 1;
for($i = 2;$i < 100;$i++)
{
$arr[$i] = $arr[$i-1] + $arr[$i-2];
}
echo join(",",$arr);// Combine arrays into 1 String output
?>
So far, the display output of Fibonacci sequence of n within 100 in Fn=F (n-1) + F (n-2) is realized.