php使用遞歸函數(shù)實(shí)現(xiàn)數(shù)字累加的方法

字號:


    這篇文章主要介紹了php使用遞歸函數(shù)實(shí)現(xiàn)數(shù)字累加的方法,涉及php遞歸操作的技巧,需要的朋友可以參考下
    本文實(shí)例講述了php使用遞歸函數(shù)實(shí)現(xiàn)數(shù)字累加的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
    <?php
    function summation ($count) {
    if ($count != 0) :
    return $count + summation($count-1);
    endif;
    }
    $sum = summation(10);
    print "Summation = $sum";
    ?>
    希望本文所述對大家的php程序設(shè)計(jì)有所幫助。