【发布时间】:2019-04-04 12:31:15
【问题描述】:
我有两个数组。第一个数组是名称,它有 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 item时,group item应该是1。有没有办法这样想?
预期结果
John - 1
Jane - 2
George - 3
Jim - 1
Jack - 2
提前谢谢你
【问题讨论】:
-
你能在这里分享你的预期输出吗