Home  >  Article  >  Backend Development  >  php递归的新有关问题

php递归的新有关问题

WBOY
WBOYOriginal
2016-06-13 12:34:38812browse

php递归的新问题

本帖最后由 iamsai 于 2013-09-28 14:04:34 编辑
<?php<br />
<br />
    reverse_i('hello');<br />
<br />
   function reverse_i($str)<br />
{<br />
  <br />
  if(strlen($str)>0)	<br />
<br />
    reverse_i(substr($str,1)); <br />
<br />
echo substr($str,0,1); <br />
<br />
//return<br />
<br />
}<br />
 /* <br />
大家看我的思路对吗?<br />
	reverse('hello');<br />
<br />
function reverse_i('hello')<br />
if(strlen('hello'))>0<br />
  reverse_i('ello');<br />
<br />
function reverse_i('ello')<br />
if(strlen('ello'))>0<br />
  reverse_i('llo');<br />
<br />
function reverse_i('llo')<br />
if(strlen('llo'))>0<br />
  reverse_i('lo');<br />
<br />
function reverse_i('lo')<br />
if(strlen('lo'))>0<br />
  reverse_i('o');<br />
<br />
function reverse_i('o')<br />
if(strlen('o'))>0<br />
   reverse('');<br />
<br />
function reverse_i('')<br />
if(strlen(''))>0<br />
此时不满足if条件就跳出if语句 <br />
执行下一句<br />
echo substr($str,0,1); <br />
打印出一个空字符程序不就结束了吗?因为没有return语句也就没有返回调用它的return('o')也无法顺势打印出后面的olleh呀<br />
可程序输出仍然是olleh...<br />
*/<br />
   <br />
?><br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article: 指令分隔符?该怎么解决 Next article: PHP诠释