Fibonacci Series
This algorithm finds the fibonacci series. In this algorithm the next number is found by adding up the two numbers before it.
Example of fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
function Fibonacci($count)
{
$numbers = array();
if ($count > 1)
{
$numbers[0] = 0;
$numbers[1] = 1;
}
$i = 2;
while ($i < $count)
{
$numbers[$i] = $numbers[$i - 1] + $numbers[$i - 2];
$i++;
}
return $numbers;
}
Example
$fibonacciNumbers = Fibonacci(10);
Output
0
1
1
2
3
5
8
13
21
34