Print Fibonacci Series In PHP

Share Now

Share on facebook
Share on pinterest
Share on twitter
Share on linkedin
Share on email

#CODE EXAMPLE


function fibonacci ($old, $new, $end){
    static $start;
    $start = $start ?? 1;
    
    if ( $start>$end ){
        return;
    }

    $start++;
    echo $old." ";
    $_temp = $old+$new;
    $old = $new;
    $new = $_temp;

    fibonacci ($old, $new, $end);
}

fibonacci ( 0, 1, 10);

Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert