"The Bible" has been confused about recursion. I can't solve the problem 555 a day.-php Tutorial

Source: Internet
Author: User
& Quot; The Bible & quot; The recursion problem is confusing for 555 of the day. This post was last edited by iamsai from 2013-09-2421: 00: 08. & lt ;? Php $ strhello; reverse_ I ($ str); function & nbsp; reverse_ I ($ str) {if (strlen ($ str "Bible") the recursion problem cannot be solved 555 a day...

This post was last edited by iamsai at 21:00:08

 
$str='hello';
reverse_i($str);
function reverse_i($str)
{
if(strlen($str)>0)
{
reverse_i(substr($str,1));

}

echo substr($str,0,1);
return;

}
?>


Please refer to my questions:
The output result of this program is the inverted olleh output.
After reverse_ I (substr ($ str, 1) in the loop body; hello ello llo lo o
Echo substr ($ str, 0, 1); output o.
What value does the return statement return? Is it returned to the fourth row? What is the subsequent execution order? Who can help me analyze? Thank you!

Share To: 0 ){?... 'Data-pics = ''>


------ Solution --------------------
If (strlen ($ str)> 0)
?? {???
???? Reverse_ I (substr ($ str, 1); // This is a recursive call.
<--- Return here
??}
?? Echo? Substr ($ str, 0, 1 );
?? Return;

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.