PHP foreach 循环中的多个索引变量 [英] Multiple index variables in PHP foreach loop
本文介绍了PHP foreach 循环中的多个索引变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 PHP 中使用具有多个索引"变量的 foreach
循环,类似于以下内容(不使用正确的语法)?
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?
推荐答案
要达到你可以做的结果
foreach (array_combine($courses, $sections) as $course => $section)
但这只适用于两个数组
这篇关于PHP foreach 循环中的多个索引变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文