I have an array and I would like to take action on every iteration
for($i = 0; $i < count($array); $i++) {
0,1,3...10
// Execute
$create->save();
11, 12, 13... 20
// Execute
$create->save();
}
I have an array and I would like to take action on every iteration
for($i = 0; $i < count($array); $i++) {
0,1,3...10
// Execute
$create->save();
11, 12, 13... 20
// Execute
$create->save();
}
You can use the modulo of 10.
for($i = 0; $i < count($array); $i++) {
if($i%10 == 0{
$create->save();
}
}
Something like this?
$n = 10;
for($i = 0; $i < count($array); $i++) {
if($n == $i) {
$create->save();
$n = $n + 10;
}
}
But here in your loops 10 != 10
, because is 11 loop. If you need to execute at every 10 loop, then $n = 9
or $i = 1
;