菜鸡求教

WBOY
Release: 2016-06-23 13:42:05
Original
1080 people have browsed it

代码如下

<?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);?>
Copy after login


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


回复讨论(解决方案)

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

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

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


改?:
<?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);?>
Copy after login


5
int(5)

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template