The confusion of the "bible" recursive problem think of 555 also no solution to the day ...

Source: Internet
Author: User
This post was last edited by Iamsai on 2013-09-24 21:00:08

 
  0) {   reverse_i (substr ($STR, 1));                } Echo substr ($STR, 0,1); return;}? >


Please look at my question:
The output of this program is the reverse output olleh.
Through the Loop body reverse_i (substr ($STR, 1)); Operation of the statement Hello Ello llo lo o
When the character length is ==0, Echo substr ($str, 0, 1); Output O.
What value is returned from the return statement? Is it back to line fourth? What is the subsequent order of execution? Who can help me analyze and analyze? Thank you, Hero!


Reply to discussion (solution)

Return, which means that the program of this function no longer runs below, the function does not need to return a value, so it is not added!

That only outputs O?

Why does it output hello, and who can help me analyze it?

You add my QQ directly,

643461761

$str = ' Hello '; Var_dump (Reverse_i ($STR)); See what function reverse_i ($str) {  echo $str, php_eol;//See what's passed in  if (strlen ($STR) >0)  {       reverse_i (Substr ($STR, 1));  }  Echo substr ($STR, 0,1);  return;}
Hello
Ello
Llo
Lo
O

Ollehnull

$str = ' Hello '; Var_dump (Reverse_i ($STR)); See what function reverse_i ($str) {  echo $str, php_eol;//See what's passed in  if (strlen ($STR) >0)  {       Reverse_ I (substr ($STR, 1));  }  Echo substr ($STR, 0,1);  return;}
Hello
Ello
Llo
Lo
O

Ollehnull
Echo substr ($str, 0, 1); function is not the first character of the output string? Does it end after you enter 0 and return NULL to the calling function program? Why is the output llehnull

if (strlen ($STR) >0)
{
Reverse_i (substr ($STR, 1)); This is a recursive call
<---back to here
}
Echo substr ($str, 0, 1);
Return

Return after the first recursion is the function body that returns o this value to if? How is it different from C language? Does not return this value directly to the function that called it?

Return after the first recursion is the function body that returns o this value to if? How is it different from C language? Does not return this value directly to the function that called it?

Return after the first recursion is the function body that returns o this value to if? How is it different from C language? Does not return this value directly to the function that called it?

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