In the previous article we introduced the use of PHP recursive functions, and the implementation of the method, then we use the PHP recursive function to return the problem? Today, we will give you an explanation of the return value in the PHP recursive function!
Return a value problem in a recursive function
/* Loop to remove the string to the left of the 0 */function Removeleftzero ($str) {if ($str [' 0 '] = = ' 0 ') {$str = substr ($str, ' 1 '); Removeleftzero ($STR);} Else{return $str;}}
In most people's view this code is not a problem, if not run a bit and do not know where the problem? If the recursion does not have a return value after this is run, there will be no return value after recursion, even if the else condition is met, and should be changed to
/* Loop to remove the string to the left of the 0 */function Removeleftzero ($str) {if ($str [' 0 '] = = ' 0 ') {$str = substr ($str, ' 1 '); return Removeleftzero ($str ); Add return value to function}else{return $str;}}
Summarize:
I believe that through this article, we have a new understanding of the return value problem in PHP recursive function, but also know how to solve it, and hope to help you!
Related recommendations:
Analysis of three ways to implement PHP recursive function
Example of using PHP recursive functions
How does php recursive function work? Typical examples of PHP recursive functions
What is PHP recursive function and simple example explanation