本文介绍了PHP foreach循环中的多个索引变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中有多个index变量可能有一个 foreach 循环,类似于以下(不使用正确的语法)?

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

如果没有,是否有一个很好的方法来实现相同的结果?

解决方案

实现这个结果你可以做

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

只适用于两个数组

Is it possible to have a foreach loop in PHP with multiple "index" variables, akin to the following (which doesn't use correct syntax)?

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

If not, is there a good way to achieve the same result?

解决方案

to achieve just that result you could do

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

but that only works for two arrays

这篇关于PHP foreach循环中的多个索引变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 00:37
查看更多