在一个foreach循环中计数迭代次数 [英] Count number of iterations in a foreach loop
本文介绍了在一个foreach循环中计数迭代次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想计算总行数。
<$ p $ foreach($ Contents作为$ item){
$ item [数字]; //如果在这个foreach中有15个$ item [数字],我想得到值:15
$ / code>
谢谢。
解决方案
count.phprel =noreferrer> count
。现在,回答你的问题...
lockquote
如何计算foreach中有多少项?
$ i = 0;
pre
foreach($ contents为$ item){
$ i ++;
$ item [number]; //如果在这个foreach中有15 $ item [number],我想得到值:15
}
你也可以看看这里的答案:
- 如何找到foreach索引
ul>How to calculate how many items in a foreach?
I want to count total rows.
foreach ($Contents as $item) { $item[number];// if there are 15 $item[number] in this foreach, I want get the value : 15 }
Thanks.
解决方案First of all, if you just want to find out the number of elements in an array, use
count
. Now, to answer your question...How to calculate how many items in a foreach?
$i = 0; foreach ($Contents as $item) { $i++; $item[number];// if there are 15 $item[number] in this foreach, I want get the value : 15 }
You could also have a look at the answers over here:
这篇关于在一个foreach循环中计数迭代次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文