如何找到foreach索引? [英] How to find the foreach index?
本文介绍了如何找到foreach索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以找到foreach
索引?
在for
循环中如下所示:
for ($i = 0; $i < 10; ++$i) {
echo $i . ' ';
}
$i
将为您提供索引.
我必须使用for
循环还是有某种方法可以在foreach
循环中获取索引?
Do I have to use the for
loop or is there some way to get the index in the foreach
loop?
推荐答案
foreach($array as $key=>$value) {
// do stuff
}
$key
是每个$array
元素的索引
这篇关于如何找到foreach索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文