如何计算一个foreach中有多少项?
我想要计算总行数.
foreach ($Contents as $item) {
$item[number];// if there are 15 $item[number] in this foreach, I want get the value : 15
}
如何计算一个foreach中有多少项?
我想要计算总行数.
foreach ($Contents as $item) {
$item[number];// if there are 15 $item[number] in this foreach, I want get the value : 15
}
如果您只想知道数组中的元素数,请使用count
.现在,为了回答你的问题...
如何计算一个森林中有多少项?
$i = 0;
foreach ($Contents as $item) {
$item[number];// if there are 15 $item[number] in this foreach, I want get the value : 15
$i++;
}
如果只需要循环内的索引,可以使用
foreach($Contents as $index=>$item) {
// $index goes from 0 up to count($Contents) - 1
// $item iterates over the elements
}