fork download
  1. <?php
  2.  
  3. function findFib($n) {
  4. $fib = [];
  5. for($i=3, $fib[1]=0, $fib[2]=1; $i<=$n; $i++) {
  6. $fib[$i] = $fib[$i-1] + $fib[$i-2];
  7. }
  8. return $fib;
  9. }
  10.  
  11. $a = [];
  12.  
  13. $a = findFib(10);
  14.  
  15. print_r($a);
  16.  
Success #stdin #stdout 0.01s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [1] => 0
    [2] => 1
    [3] => 1
    [4] => 2
    [5] => 3
    [6] => 5
    [7] => 8
    [8] => 13
    [9] => 21
    [10] => 34
)