PHP _ Bug_PHP tutorial for returning recursive functions

Source: Internet
Author: User
The return Bug in PHP _ recursive functions. I recently used PHP to write small examples of design patterns. a large number of design patterns call objects or functions recursively. Sometimes return is required to return the processing status. In JAVA, I recently used PHP to write small examples of design patterns. a large number of design patterns call objects or functions recursively. Sometimes return is required to return the processing status. In JAVA, you only need to return the result within the function. In PHP, you must add return to the recursive function before it can be used normally.

For example


01
02
/**
03
* When calling this method, you need to call the function recursively when $ I <3. If it is in JAVA, the $ I value can be returned, 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: si Yun Qilin

Bytes. Sometimes return is required to return the processing status. In JAVA...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.