Dev Diaries WD logo Dev Diaries WD
PHP INTERVIEW · EP 06
PHP INTERVIEW · Episode 06

Print the Fibonacci series in PHP

The classic loop-logic interview question

ep6_fibonacci_series.php
function fibonacci($number){
  $numberOne = 0;
  $numberTwo = 1;
  $numbersArray = [$numberOne,$numberTwo];

  for($i=0;$i<$number;$i++){
      $numberThree = $numberOne + $numberTwo;
      $numbersArray[] = $numberThree;
      $numberOne = $numberTwo;
      $numberTwo = $numberThree;

  }
  return $numbersArray;
}


$numberOfDigits = 20;
 $output = fibonacci($numberOfDigits);
 
Output
Output for this tutorial goes here.
01123581321345589144233377610987159725844181676510946

This is the actual output....

Watch the full episode

Watch on YouTube