function fibonacci($n) {
        $fib = [];
        $fib[0] = 0;
        $fib[1] = 1;

        for ($i = 2; $i < $n; $i++) {
            $fib[$i] = $fib[$i - 1] + $fib[$i - 2];
        }

        return $fib;
    }

    // Generate and display the Fibonacci series
    $n = 10; // Number of Fibonacci numbers to generate
    $fibonacciSeries = fibonacci($n);

    echo "Fibonacci series of $n numbers: ";
    foreach ($fibonacciSeries as $number) {
        echo $number . " ";
    }

Leave a Reply

Your email address will not be published. Required fields are marked *