Home > Article > Backend Development > Playing with PHP recursive functions: The ultimate solution to the return value problem of PHP recursive functions
In PHP recursive functions, we often encounter the problem that the recursive function has no return value. So how to correctly handle the return value in the recursion implemented in PHP? What to do if the PHP recursive function has no return value? You can refer to the example analysis of this article.
1. Return value of php recursive function Example 1: Copy code Code example:function test($i){ $i-=4; if($i test($i); } } echo test(30)." "; Note that there is a problem with else in the above code. When the condition $i Example 2, modify the php recursive function to: Copy code Code example:function test($i){ $i-=4; if($i return test($i); } } echo test(30)." "; 2. PHP recursive function return value problem |