Fibonacci Sequence

Generate the first N numbers of the Fibonacci sequence where each number is the sum of the two preceding ones.

Code

Algorithms
$fib = [0, 1];
for ($i = 2; $i < $n; $i++) $fib[] = $fib[$i-1] + $fib[$i-2];
array_slice($fib, 0, $n);

Parameters

Number of Fibonacci numbers to generate

Server

More PHP Snippets