DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Teddy Zugana
Teddy Zugana

Posted on

PHP Recursive Fibonacci

<?php
  $inputdata = @$_POST[β€˜inputdata’];  if(empty($inputdata))
  {
   $inputdata = @$_GET[β€˜inputdata’];
  }  

  $result = array();
  if(is_numeric($inputdata))
  {
   if(!empty($inputdata))
   {

    $result = array();

    for ($i = 0; $i < $inputdata; $i++)
    {  
        $dataseriestemp=series($i); 
        if($dataseriestemp==0)
        {
        }
        else if($dataseriestemp%2==1)
        {
          $result[]=$dataseriestemp;
        } 
     } 
   }
 }

function series($num)
{ 
 if($num == 0)
 { 
   return 0; 
 }
 else if($num == 1)
 { 
   return 1; 
 } 
 else 
 { 
   return (series($num-1) + series($num-2)); 
 } 
}

rsort($result);
header(β€˜Content-Type: application/json’);
echo json_encode($result);
?>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›