I have two arrays. The first array is names and it has 5 names. The second array is groups and it has 3 groups. I want to loop through both of the arrays and set each index name to the index group. If the group index finishes I want to restart the second array.
I tried reseting the group index to 0 if it reaches the last item but it doesn't work.
$names = [
'John',
'Jane',
'George',
'Jim',
'Jack'
];
$groups = [
'1',
'2',
'3'
];
foreach ($names as $index => $name) {
$result = "The student: " . $name . " belongs to the: " .$groups[$index]. "group" ;
echo ($result);
echo "<br>";
echo "<br>";
}
When it reaches the fourth name item, the group item should be 1. Is there a way to do such think?
Expected outcome
John - 1
Jane - 2
George - 3
Jim - 1
Jack - 2
Thank you in advance