【发布时间】:2015-02-04 06:48:56
【问题描述】:
在递归函数中返回值有一些问题。但我可以附和它。 这有什么问题?
function calculate($i,$count=1)
{
$str_i = (string)$i;
$rslt = 1;
for ($k=0; $k<strlen($str_i); $k++) {
$rslt = $str_i[$k]*$rslt;
}
if ( strlen((string)$rslt) > 1 ) {
$this->calculate($rslt,++$count);
} elseif ( strlen((string)$rslt) == 1 ) {
return $count;
}
}
【问题讨论】:
-
这个函数的目标是什么?你能提供一个测试输入吗?如果
strlen((string)$rslt) == 0永远不会返回。 -
感谢您的回复!这个函数计算加德纳数!