2 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊
根據(jù)錯(cuò)誤,聽(tīng)起來(lái)您好像是在使用$numRows字符串,但這必須在代碼中更遠(yuǎn)的地方,這是您尚未發(fā)布的內(nèi)容。$numRows()我相信您可以調(diào)用函數(shù),但是在內(nèi)部$numRows,您可以使用$total。正如Zain Farooq所建議的那樣,您也許可以,use ($total)但是最好$total將函數(shù)參數(shù)作為參數(shù)傳遞。例子:
$total = mysqli_num_rows($result);
$getNumRows = function($tot)
{
if($tot <= 4){
return 1;
} else {
return ($tot / 4);
}
};
$result = $getNumRows($total);
echo "I have {$result} rows.";
我認(rèn)為您正在執(zhí)行的操作,在某處正在執(zhí)行類似的操作echo $numRows,但是它必須是echo $numRows(),因此函數(shù)被調(diào)用了。

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
你的問(wèn)題就在這里
$numRows = (function() use ($total) {
if($total <= 4){
return 1;
}else{
return ($total / 4);
}
})();
您必須在括號(hào)之間包裝函數(shù),如果要傳遞參數(shù),則應(yīng)使用 use()
- 2 回答
- 0 關(guān)注
- 149 瀏覽
添加回答
舉報(bào)