Home >Backend Development >PHP Tutorial > php 递归方法返回值 为null 有关问题

php 递归方法返回值 为null 有关问题

WBOY
WBOYOriginal
2016-06-13 12:55:051166browse

php 递归方法返回值 为null 问题

本帖最后由 lihaiboas1 于 2013-01-28 13:31:03 编辑
<br />
function getcount($start,$str){<br />
	//echo "查找".$str."中 出现 ".$start."<br/>";<br />
	$findstr=$start.(string)((int)substr($start,-1)+1);<br />
	//echo substr_count($str,$findstr)."<br/>";<br />
	if(substr_count($str,$findstr)==0){<br />
		echo "匹配结束".$start."<br/>";<br />
		var_dump($start);<br />
		return $start;<br />
	}else{<br />
		echo "匹配".$findstr.",继续递归匹配<br/>";<br />
		var_dump($findstr);<br />
		getcount($findstr,$str);<br />
	}<br />
}<br />
<br />
$a="7641235123"; <br />
for($i=0;$i<10;$i++){<br />
	$str1=getcount($i,$a);<br />
	var_dump($str1);//为什么返回的是null呢?<br />
	if(strlen($str1)>1){<br />
		echo "$a 出现重复字符 ".$str." 共 ".substr_count($a,$str). "次<br/>";<br />
	}<br />
}<br />



------解决方案--------------------
12 行的
        getcount($findstr,$str);
改为
        return getcount($findstr,$str);
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