Home > Backend Development > PHP Tutorial > PHP_Bug in return when recursive function_PHP tutorial

PHP_Bug in return when recursive function_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:52:33
Original
962 people have browsed it

Recently I am writing some small examples of design patterns in PHP. There are a large number of design patterns that call objects or functions recursively. Sometimes you need to return to the processing status, you will use return. In JAVA, you can get the final result by simply returning inside the function. In PHP, you must add return when passing a recursive function to use it normally.

Give me an example


01
02
/**
03
*When calling this way of writing, when $i < 3, the function needs to be called again recursively. If it is in JAVA, you can return the value of $i, but PHP cannot.
04
*/
05
function TestReturn($i){
06
If($i < 3)
07
{
08
         $i++;
09
         TestReturn($i);
10
}
11
Return $i;
12
}
13

14
/**
15
*In PHP, you must add return
when calling a function recursively 16
*/
17
function TestReturn($i){
18
If($i < 3)
19
{
20
         $i++;
21
         return TestReturn($i);
22
}
23
Return $i;
24
}
25

26
?>


Author: Siyun Qilin

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478112.htmlTechArticleRecently I am writing some small examples of design patterns in PHP. There are a large number of design patterns that call objects or functions recursively. Sometimes you need to return to the processing status, you will use return. In JAVA...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template