Call a function after every n loops in foreach?
<p>There's a foreach loop in my code, on which the progress of a task depends. Right now, there's no way I could find which loop is ongoing in the foreach loop. Ultimately, I cannot track the progress.</p>

<p>Is there any better way than including an incrementing variable and checking if it has crossed n loops?</p>

<p>In short: Anyway to improve the following function?</p>

<p>Example:</p>

<pre><code>&lt;?php
$counter = 1;
$theN = 100;
foreach( $allLoops as $thisLoop ) {
    /*
    The code to perform the "task"
    */
    if( $counter%$theN == 0 ) {
        theFunction();
    }
    $counter++;
}
</code></pre>
