This article mainly introduces PHP based on simple recursive function to find a number of factorial method, combined with the example of the PHP recursive function definition and mathematical operation of simple operation skills, the need for friends can refer to the next
In this paper, we describe a method for calculating the factorial of a number based on simple recursive function of PHP. Share to everyone for your reference, as follows:
First, the question:
To find the factorial of a number A, then a!=a* (A-1) * (a-2) * (a-3) *......*2*1. For example, 6 factorial 6! =6*5*4*3*2*1=720. So, how do you get the factorial of any number by using PHP code?
Second, the implementation of code:
<?phpfunction Demo ($a) { if ($a > 1) { $r = $a * Demo ($a-1); } else { $r = $a; } return $r;} $a = 6;echo $a. "The value of the factorial." Demo ($a);? >
Third, show the result:
The above is the whole content of this article, I hope that everyone's study has helped.