Step inside foreach

foreach, php

Solution

Use modulo to determine offset.

$i = 0;

foreach ($array as $a) {
   $i++;
   if ($i % 5 == 0) {
       // your code for every 5th item
   }

   // your inside loop code
}

Problem

How to do something every 5 (for example) cycles inside foreach? I'm add `$i++` How to check it by step?

Original source