Php recursion New question this post was last edited by iamsai in 2013-09-2814: 04: 34 & lt ;? Php & nbsp; reverse_ I (hello); & nbsp; function & nbsp; reverse_ I ($ str) {& nbsp; & 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