Source:
function fibonacci($n) {
    if ($n < 2) {
        return $n;
    }
    return fibonacci($n - 1) + fibonacci($n - 2);
}
Sample Usage:
echo fibonacci(8);
// output is 21

By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.

Pythoneer 3 years ago