菜鸡求教

WBOY
WBOYOriginal
2016-06-23 13:42:051062browse

代码如下

<?phpfunction Contrast($arr,$r,$c,&$numb){	if($arr[$r][$c]==$arr[$r][$c+1]){		$c++;		$numb++;				Contrast($arr,$r,$c,$numb);			}else{	  	  echo $numb."</br>";	  return  $numb;	  	}}$arr=array(array(0,0,0,1,1,1,1,1,1,0,0,));$r=0;$c=3;$numb=0;$d=Contrast($arr,$r,$c,$numb);var_dump($d);?>


输出是
为什么函数没有返回值啊?


回复讨论(解决方案)

第6行 加上return  :return Contrast($arr,$r,$c,$numb);

??分支的???有返回值

    if($arr[$r][$c]==$arr[$r][$c+1]){        $c++;        $numb++;               Contrast($arr,$r,$c,$numb);           }else{ 


改?:
<?phpfunction Contrast($arr,$r,$c,&$numb){    if($arr[$r][$c]==$arr[$r][$c+1]){        $c++;        $numb++;               return Contrast($arr,$r,$c,$numb);           }else{            echo $numb."</br>";      return  $numb;          }} $arr=array(array(0,0,0,1,1,1,1,1,1,0,0,));$r=0;$c=3;$numb=0;$d=Contrast($arr,$r,$c,$numb);var_dump($d);?>


5
int(5)

谢谢各位大神 已经想明白了!~~~~

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