1
我的代碼中存在一個foreach循環,任務的進度取決於該循環。現在,我無法找到foreach循環中正在進行的循環。最終,我無法追蹤進展。在foreach中的每個循環之後調用一個函數?
有沒有比包含遞增變量和檢查它是否跨越n個循環更好的方法?
總之:無論如何改善以下功能?
例子:
<?php
$counter = 1;
$theN = 100;
foreach($allLoops as $thisLoop) {
/*
The code to perform the "task"
*/
if($counter%$theN == 0) {
theFunction();
}
$counter++;
}
你能舉個例子嗎? –
@Daniel添加了它。 – kapeels