Home > Backend Development > PHP Tutorial > How to make good use of PHP recursive function return values ​​and return statements? Detailed examples

How to make good use of PHP recursive function return values ​​and return statements? Detailed examples

WBOY
Release: 2016-07-25 08:51:24
Original
1757 people have browsed it
Solutions to the problem of return values ​​​​from PHP recursive functions, as well as some points to pay attention to when using return statements in PHP recursive functions to return values, and correctly handle the return values ​​​​of PHP recursive functions to make the code more robust.

The return value problem of php recursive function

Example:

Copy code Code example:

There is a problem in else in the above code. The test executed here has no return value. Therefore, although the condition $i

Make the following modifications to the above php recursive function:

Copy code Code example:

Notes on return values ​​in php recursive functions

When using return in a PHP recursive function, you will encounter situations where the desired value cannot be returned correctly. If you don’t understand the reason, it will be difficult to find the error.

Example:

Copy code Code example: function test($i){ $i-=4; if($iIn fact, there is a problem in the else of this function. The result of execution in this code has no return value. So even if the condition $i Copy code Code example: function test($i){ $i-=4; if($i


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template