A brief analysis of PHP recursive function return value using method _php Tutorial

Source: Internet
Author: User
PHP after a long time of development, many users are very familiar with PHP, PHP was originally created in 1994 Rasmus Lerdorf, just started a simple Perl language program, used to count his own site visitors. It was later rewritten in C, including access to the database.


Starting with personal Home Page tools (PHP Tools) in 1995, Lerdorf wrote some documents describing the program and released PHP1.0. In this early version, the guest message book, guest counter and other simple functions are provided. More and more Web sites later used PHP, and strongly asked to add some features, such as loop statements and array variables, after the new members joined the development ranks, in 1995 years, PHP2.0 released. The second edition is named PHP/FI (Form interpreter). Php/fi joined the support for mSQL, and has since established PHP's position in Dynamic web development. By the end of 1996, there were 15,000 websites using PHP/FI, and in 1997 years the number of sites using PHP/FI was more than 50,000. In the 1997 years, the third edition of the development Plan began, the development team joined Zeev Suraski and Andi Gutmans, and the third edition was named PHP3. In the 2000, PHP4.0 was introduced, which added many new features.

In my previous programming encountered a PHP recursive function problem, in fact, is a very simple problem. The problem is with the return value of the PHP recursive function. This is the beginning of the writing:

Copy the Code code as follows:
FunctionTest ($i)
{
$i-=4; if ($i <3)
{
return$i;
}
Else
{
Test ($i);
}
}
Echotest (30);
?>

This code does not seem to be a problem, in fact there is an else inside there is a problem. The test executed here does not return a value. So while the condition $i<3 is satisfied return$i the entire function still does not return a value. Make the following changes to the PHP recursive function above:

Copy the Code code as follows:
FunctionTest ($i)
{
$i-=4; if ($i <3)
{
return$i;
}
Else
{
Returntest ($i);//Add return, let function return value
}
}
Echotest (30);
?>

http://www.bkjia.com/PHPjc/326604.html www.bkjia.com true http://www.bkjia.com/PHPjc/326604.html techarticle PHP After a long time of development, many users are very familiar with PHP, PHP was originally created in 1994 Rasmus Lerdorf, just started a simple Perl language program, used to statistics ...

  • 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.