How to use tail Recursion in php
This article mainly shows you "how to use tail recursion in php", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to use tail recursion in php" this article bar.
The concept of tail recursion
The concept of tail recursion is a subset of the concept of recursion. For ordinary recursion, the overhead is incalculable because you have to remember the recursive call stack. For example, the first example in the php section below uses php to write a factorial function, which is due to the stack overflow error caused by recursion. The purpose of tail recursion is to eliminate the defect of recursive stack loss.
From the code level, tail recursion can be clearly stated in one sentence:
The last operation of the function is a recursive call
For example, the recursive implementation of php of the "Fibonacci" sequence:
The code is as follows:
fibonacci.php