Home >Backend Development >PHP Tutorial >"圣经"递归有关问题的困惑 想了一天555也无解.

"圣经"递归有关问题的困惑 想了一天555也无解.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:38:41928browse

"圣经"递归问题的困惑 想了一天555也无解...

本帖最后由 iamsai 于 2013-09-24 21:00:08 编辑
<?php<br /><br />	$str='hello';<br />	reverse_i($str);<br />	function reverse_i($str)<br />	{<br />		if(strlen($str)>0)<br />		{   <br />			reverse_i(substr($str,1));<br />			<br />                }<br />		<br />		echo substr($str,0,1);<br />		return;<br /><br />	}<br />?>


请大家看我的问题:
此程序的输出结果是倒序输出 olleh .
经过循环体中reverse_i(substr($str,1));语句的操作 hello ello llo lo o 
当字符长度==0时,echo substr($str,0,1); 输出o.
return语句返回什么值呢?是返回到第四行?后面的执行顺序是什么呢?有谁能帮我分析分析?谢谢大侠了!
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