<?php
/* reading O(n) */
function fib($n)
{

	$num1 = 0;
	$num2 = 1;
	$sum = 0;
	
	for($i=0; $n > $i; $i++){
		
		if($i < 2){
			echo "$i";
			echo " ";
		}else{		
			echo $sum = $num1 + $num2;
			echo " ";
			
			$num1 = $num2;
			$num2 = $sum;
		}
	}
}

fib(10); // 0 1 1 2 3 5 8 13 21 34 
<?php
/* O(n) */
function fib($n, $n1, $n2)
{
	$nn1 = $n2;
	$nn2 = $n1 + $n2;
	
	if($n < 1) return;
	
	echo $n1;
	echo " ";
	return fib($n - 1 , $nn1, $nn2);
}

fib(10, 0 , 1); // 0 1 1 2 3 5 8 13 21 34 

Get fib number without generating entire array reading O(1)

<?php

/* 
* reading single Fibonacci number  
* O(1)
*/
function getFib($n)
{
    $fibNum = round(((5 ** .5 + 1) / 2) ** $n / 5 ** .5);
    return $fibNum;
}

/* reading O(1) */
echo getFib(0); // 0
echo getFib(9); // 34
echo getFib(10); // 55

/* reading O(n) */
$n = 0;
while($n < 10){
	echo getFib($n) . " ";
	$n++;
} // 0 1 1 2 3 5 8 13 21 34

https://sandbox.onlinephpfunctions.com/
https://www.mathsisfun.com/numbers/fibonacci-sequence.html
https://stackoverflow.com/questions/15600041/php-fibonacci-sequence
https://en.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding

0
Would love your thoughts, please comment.x
()
x