Home >Backend Development >PHP Tutorial >Playing with PHP recursive functions: The ultimate solution to the return value problem of PHP recursive functions

Playing with PHP recursive functions: The ultimate solution to the return value problem of PHP recursive functions

WBOY
WBOYOriginal
2016-07-25 08:51:262329browse
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



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn