Xin Xing and your interpretation of PHP recursion & nbsp; actually, recursion in other programming languages may be a exercise for beginner functions, but due to the particularity of PHP, let's take it out and explain it in detail. First, let's talk about what recursion means. I first realized that recursion is a factorial of a number. for example, if we write a function, then, calculate the factorial value. & Nbsp; check the following PHP code: & lt ;? Php evaluate n! Fu Xinxing and your interpretation of PHP recursion
Actually, recursion may be an exercise for beginners in other programming languages. However, due to the special nature of PHP, let's take it out and explain it in detail. First, let's talk about what recursion means, I first knew that recursion is to find a factorial of a number. for example, we write a function and then calculate its factorial.
See the following PHP code:
0) {return $ n * xin ($ n-1);} else {return 1 ;}} echo xin (4 );The output result is of course 24. what does it mean? it is very simple. we pass a value to the xin function. if it is larger than 0, then multiply it by the result of calling the $ n-1 xin function. of course, the reader may have N ways to calculate the n factorial, but no doubt, this is calculated using recursion.
It can be seen that the recursion in PHP is similar to the mathematical induction method of high school learning. The principle is very simple and easy to understand. The general step is to first determine whether or not downward recursion is required. if so, a rule is provided. if not, a timely response is required to give control to its caller, there are so many things about the basic principles. write them here first.