<分区>
我有两个数组。第一个数组是名称,它有 5 个名称。第二个数组是组,它有 3 个组。我想遍历这两个数组并将每个索引名称设置为索引组。如果组索引完成,我想重新启动第二个数组。
如果它到达最后一项,我尝试将组索引重置为 0,但它不起作用。
$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>";
}
当到了第四个name项时,group item应该是1,有没有办法这样想?
预期结果
John - 1
Jane - 2
George - 3
Jim - 1
Jack - 2
提前致谢