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

时间:2012-02-10 10:39:34

标签: php variables loops foreach

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

任何添加超过2的方法?

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

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

1 个答案:

答案 0 :(得分:3)

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

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