<?php $num = 7; function add($num){ static $total = 0; if($num>=1){ $total+=$num; add(--$num); }else{ return $total; } } var_dump(add($num));
int(28)
NULL
string(0) ""
int(0)
完全没注意return
return
<?php $num = 7; function add($num){ static $total = 0; if($num>=1){ $total+=$num; add(--$num); }else { return $total; } return $total; } var_dump(add($num)); ?> //上述代码少了一句return $total;
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题