Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting foreach to skip over iterations

Tags:

php

I basically need something inside a foreach loop that will skip over the first 10 iterations of the array.

foreach($aSubs as $aSub){
   if($iStart > '0')
   //Skip first $iStart iterations.  Start at the next one
}

Thanks

like image 299
tmartin314 Avatar asked Oct 02 '10 22:10

tmartin314


1 Answers

Start a counter and use continue to skip the first ten loops:

$counter = 0 ;
foreach($aSubs as $aSub) {
    if($counter++ < 10) continue ;
    // Loop code
}
like image 73
Gus Avatar answered Oct 20 '22 22:10

Gus