New issues related to php recursion

Source: Internet
Author: User
Php recursion New question this post was last edited by iamsai in 2013-09-2814: 04: 34 & lt ;? Php & nbsp; reverse_ I ('Hello'); & nbsp; new php recursion problems
This post was last edited by iamsai at 14:04:34
 
Reverse_ I ('Hello ');

Function reverse_ I ($ str)
{

If (strlen ($ str)> 0)

Reverse_ I (substr ($ str, 1 ));

Echo substr ($ str, 0, 1 );

// Return

}
/*
Are you sure you want to look at my ideas?
Reverse ('Hello ');

Function reverse_ I ('Hello ')
If (strlen ('Hello')> 0
Reverse_ I ('ello ');

Function reverse_ I ('ello ')
If (strlen ('ello ')> 0
Reverse_ I ('llo ');

Function reverse_ I ('llo ')
If (strlen ('llo')> 0
Reverse_ I ('Lo ');

Function reverse_ I ('Lo ')
If (strlen ('Lo')> 0
Reverse_ I ('o ');

Function reverse_ I ('o ')
If (strlen ('o')> 0
Reverse ('');

Function reverse_ I ('')
If (strlen ('')> 0
If the if statement does not meet the if condition
Execute the next sentence
Echo substr ($ str, 0, 1 );
Isn't the process of printing out an empty character? Because there is no return statement, the return ('o') that calls it will not be able to print out the olleh behind it.
Program output is still olleh...
*/

?>
Share To: 0 )???? Reve... 'data-pics = ''>
------ Solution --------------------
Obviously, it is output ..
Your program can be viewed
$ Str = 123;
If (strlen ('123')> 0)
 
// Reverse_ I ('23 ');
If (strlen ('23')> 0 ){
// Reverse_ I ('3 ');
If (strlen ('3')> 0 ){
// Reverse_ I (''); no, and then execute the following statement
Echo substr ('3', 0, 1); // output 3
}
Echo substr ('23', 0, 1); // output 2
}
 
Echo substr ('100', 123); // output 1

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.