在遞歸函數中返回值時出現問題。但我可以迴應它。 這有什麼不對?在遞歸函數中返回值的問題PHP
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',則永遠不會返回。 – 2014-12-06 01:24:51
感謝您的回覆!這個函數計算加德納的數字! – Alliswell 2014-12-06 10:06:44