I have a foreach in which I have three different arrays. I want to put the value – when running the foreach – in the different arrays every third time (look example below for better explanation).
Ex: arr = blue, red, green, yellow, brown
arr1 = blue, yellow arr2 = red, brown arr3 = green
I have this code (but dont work because the modulus doesn’t come down to the last if statement more then the first execution of the if).
$count = 0;
foreach($values as $value){
if($count%2){
$arrSecond[] = $value[img][url];
}
else if($count%3){
$arrThird[] = $value[img][url];
}
else {
$arrFirst[] = $value[img][url];
}
$count++;
}
How can I solve this?
You need to be using modulus 3 the whole time only with different offsets: