Recently, in a small example of writing design patterns in PHP, there are a number of design patterns that recursively call objects or functions. Sometimes you need to return to the processing state, you will use return. In Java, you can get the final result as long as you return inside the function. In PHP, you must add a return to the recursive function to use it normally.
As an example,
01
02
/**
03
* Such a notation is called when $i < 3 o'clock need to re-call the function recursively. If it is in Java, you can return the value of $i, and PHP will not.
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 a return to the recursive call function
16
*/
17
function Testreturn ($i) {
18
if ($i < 3)
19
{
20
$i + +;
21st
Return Testreturn ($i);
22
}
23
return $i;
24
}
25
26
?>
Author: Four Yun Kylin
http://www.bkjia.com/PHPjc/478112.html www.bkjia.com true http://www.bkjia.com/PHPjc/478112.html techarticle recently, in a small example of writing design patterns in PHP, there are a number of design patterns that recursively call objects or functions. Sometimes you need to return to the processing state, you will use return. In Java ...