fibonacci in php

<?php
if(!empty($_GET['upto'])){
$upto = $_GET['upto'];
}else{
$upto = "";
}


function getfibo($upto=5){

$second =1; 

$first  =0;
$fibo_arr[] = $first;
$fibo_arr[] = $second;

for($i=1; $i<$upto; $i++){

$fibo_arr[]= ($fibo_arr[$i-1] + $fibo_arr[$i]);

}

$fseries =  implode(',',$fibo_arr);

return $fseries;

}

echo getfibo($upto);

?>

Leave a Reply

Your email address will not be published. Required fields are marked *