The new problem of PHP recursive

<?php

    reverse_i('hello');

   function reverse_i($str)
{
  
  if(strlen($str)>0)	

    reverse_i(substr($str,1)); 

echo substr($str,0,1); 

//return

}
 /* 
You see my thoughts of you? 
	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
At this point do not satisfy the if condition is out of the if statement 
The execution of a sentence
echo substr($str,0,1); 
Print out a null procedure without end? Because there is no return statement did not return calls its return ('o') cannot homeopathic print out behind the olleh.
Programmable output is still olleh...
*/
   
?>

Started by Bancroft at October 30, 2016 - 11:14 PM

Function regardless of whether the return statement, will be after the function is executed, continue to implement the function call program

Posted by Bruce at November 01, 2016 - 11:25 PM

Do you want to meet your request should be changed to:
<?php
 
    reverse_i('hello');
 
   function reverse_i($str)
{
   
  if(strlen($str)>0) { 
  reverse_i(substr($str,1)); 
}else{//Plus else or will print out
 echo substr($str,0,1); 
//return
}
 

 
}


You have a perception problem, according to your last echo will still be executed

Posted by Elliot at November 15, 2016 - 11:37 PM

Obviously to output.
Your program can be regarded as such
$str=123;
if(strlen('123')>0)

//reverse_i('23');
if(strlen('23')>0){
//reverse_i('3');
if(strlen('3')>0){
//reverse_i(''); Fit, and then back statement execution
echo substr('3',0,1);//The output of 3
}
echo substr('23',0,1);//The output of 2
}

echo substr('123',0,1);//The output of 1

Posted by Ward at November 29, 2016 - 12:18 AM

Do you want to meet your request should be changed to:
<?php
 
    reverse_i('hello');
 
   function reverse_i($str)
{
   
  if(strlen($str)>0) { 
  reverse_i(substr($str,1)); 
}else{//Plus else or will print out
 echo substr($str,0,1); 
//return
}
 

 
}


You have a perception problem, according to your last echo will still be executed

Posted by Elliot at December 08, 2016 - 1:04 AM

If your program into if, probably the process is such

<?php
if(strlen('hello')>0){
if(strlen('hello')>0){
if(strlen('llo')>0){
if(strlen('lo')>0){
if(strlen('o')>0){
if(strlen('')>0){//You think the only output the empty, in fact, the front have execution
echo substr('',0,1);
}
echo substr('o',0,1);
}
echo substr('lo',0,1);
}
echo substr('llo',0,1);
}
echo substr('ello',0,1);
}
echo substr('hello',0,1);//Will be executed
}
?>

Posted by Elliot at December 10, 2016 - 1:36 AM

Is it?


<?php
$str='hello';

function reverse_i($str,$o_str =''){

	$str = substr($str, 1);
	$o_str .= $str.'<br>';
	strlen($str) > 0 && $o_str = reverse_i($str,$o_str);
	return $o_str;
 }



echo reverse_i($str);




Posted by Griffith at December 21, 2016 - 1:42 AM