The recursion problem of the Bible cannot be solved 555 a day... This post was last edited by iamsai at 21:00:08
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!
Reply to discussion (solution)
Return is the meaning of return, so the program of this function no longer runs below, and the function does not need to return values, so it is not added!
Can only output o?
Why does it output hello? Can someone help me analyze it?
You can add QQ directly,
643461761
$ Str = 'hello'; var_dump (reverse_ I ($ str); // check the function reverse_ I ($ str) {echo $ str, PHP_EOL; // Check 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); // check the function reverse_ I ($ str) {echo $ str, PHP_EOL; // Check if (strlen ($ str)> 0) {reverse_ I (substr ($ str, 1);} echo substr ($ str, 0, 1 ); return ;}Hello
Ello
Llo
Lo
O
OllehNULL
Echo substr ($ str,); isn't the first character of the output string? After 0 is input, will return NULL and call the function program end? Why is llehNULL output?
If (strlen ($ str)> 0)
{
Reverse_ I (substr ($ str, 1); // This is a recursive call.
<--- Return here
}
Echo substr ($ str, 0, 1 );
Return;
After the first recursion, is Return the function body that returns the value of o to if? Why is it different from C? Isn't this value directly returned to the function that calls it?
After the first recursion, is Return the function body that returns the value of o to if? Why is it different from C? Isn't this value directly returned to the function that calls it?
After the first recursion, is Return the function body that returns the value of o to if? Why is it different from C? Isn't this value directly returned to the function that calls it?