How can I detect 2nd and 3rd iteration
Here's what I did but It doesn't give the right answer
$sample_array = array('boom 1','boom 2','boom 3','boom 4','boom 5','boom 6','boom 7');
$separator2 = 0;
$separator3 = 0;
foreach($sample_array as $sample_array_value){
if(++$separator3 % 3 == 0)
{
echo $sample_array_value."<br /><br /> Separator 3 <br /><br />";
}
else if(++$separator2 % 2 == 0)
{
echo $sample_array_value."<br /><br /> Separator 2 <br /><br />";
}
else
{
echo $sample_array_value."<br />";
}
}
the output of that code is:
boom 1
boom 2
Separator 2
boom 3
Separator 3
boom 4
boom 5
Separator 2
boom 6
Separator 3
boom 7
Which is wrong, I need the output to be:
boom 1
boom 2
Separator 2
boom 3
Separator 3
boom 4
Separator 2
boom 5
boom 6
Separator 2
Separator 3
boom 7