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?