PHP Third Day

Source: Internet
Author: User

1, recursion: In the function of the body directly or indirectly call themselves.

The tedious and repetitive calling program in the refiner, and performs some more complex operation actions.


<?php


/**

* @author blog.anchen8.net

* @copyright 2014

*

*

* Declare a function named test for testing recursion

* $param int $n requires an integer as a parameter

*

*

*

*/

function test ($n) {//declares an argument named Test that has a parameter

echo $n. "         &nbsp;&nbsp; "; Outputs the function's value and two spaces at the beginning of a function

if ($n >0) {//Determine if the parameter is greater than 0

Test ($n-1); Call yourself if the parameter is greater than 0, and pass the parameter minus 1 again

} else {//Determine if the parameter is not greater than 0

echo "<-->"; Output delimited string

echo $n. "    &nbsp;&nbsp; "; Output parameter values and two spaces at the end of a function

}

echo $n. "    &nbsp;&nbsp; "; Output parameter values and two spaces at the end of a function

}


Test (10); Call the test function integer 10 to the parameter

?>


Results: 9 8 7 6 5 4 3 2 1 0 <-->0 1 2 3 4 5 6 7 8 9 10




Still don't understand .....


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.