What in layman's terms is a Recursive Function using PHP

前端 未结 16 1316
庸人自扰
庸人自扰 2020-11-22 05:50

Can anyone please explain a recursive function to me in PHP (without using Fibonacci) in layman language and using examples? i was looking at an example but the Fibonacci to

16条回答
  •  没有蜡笔的小新
    2020-11-22 06:30

    This is a very simple example of factorial with Recursion:

    Factorials are a very easy maths concept. They are written like 5! and this means 5 * 4 * 3 * 2 * 1. So 6! is 720 and 4! is 24.

    function factorial($number) { 
    
        if ($number < 2) { 
            return 1; 
        } else { 
            return ($number * factorial($number-1)); 
        } 
    }
    

    hope this is usefull for you. :)

提交回复
热议问题