/** * @param $n * * @return int */ function caller($number) { echo "Fibonacci series recursive: "; for ($i = 0; $i < $number; $i++) { echo fibonacciRecursive($i) . ' '; } echo "<br><br>"; }
/** * Recursive function which takes as parameter an integer and returns the value at the position of the fibonacci sequence. * * @param $pos int * @return int */ function fibonacciRecursive($pos) { if ($pos == 0) { return 0; } else { if ($pos == 1) { return 1; } else { return fibonacciRecursive($pos - 1) + fibonacciRecursive($pos - 2); } } }