多个变量通过 php 中的 foreach 访问


Multiple variables access through foreach in php

foreach ($courses as $course, $sections as $section, $example as $example)

有什么方法可以添加 2 个以上吗?

我只知道 2 个变量的解决方案。

foreach (array_combine($courses, $sections) as $course => $section)

如果所有数组都有相同的键,则

foreach ($courses as $key => $course)
{
    echo $sections[$key], $example[$key];
}