How to Generate Fibonacci series in PHP

previous post we have generated How to Create Triangle in PHP, in this post i will share script which will generate Fibonacci using php, this is very common type question in interview. The programming languages can be vary but question will same how to generate Fibonacci series.

Checkout other PHP Interview Queations,

Below is code for generate Fibonacci series less than 100 number:

Select Code
1
2
3
4
5
6
7
8
9
10
/* fibonancy series of sum of less than 100 number*/  
   $temp = "";  
   echo $x = 1;  
   echo $y = 4;  
  
   while($x + $y < 100){   
      echo "  " . $temp = $x + $y;  
      $x = $y;  
      $y = $temp;  
  }