I am trying to create a php foreach statement that outputs different code for the first 5 iterations, and then does a different output for the rest.
I found this snippet, which does a break at a given limit, but how could I continue from the last iteration on another foreach loop? That’s probably not the best way to do it anyways.
$i = 0;
foreach ($arr as $k => $v) {
/* Do stuff */
if (++$i == 2) break;
}
Is this possible? How would I go about it?
Thanks!
Zeem
You can use
array_slicefor this: