Doctrine2 获取集合中当前项目的索引
Doctrine2 get index of current item in collection
如何在 doctrine2 集合的循环中获取当前项目的索引?我尝试了以下方法,但它 returns 总是所有项目的数量
$items = $element->getItems();
echo $items->count() // 12
foreach ($items as $item) {
echo $items->key(); // 12
}
尝试使用 indexOf
方法:
foreach ($items as $item) {
echo $items->indexOf($item); // the index
}
如何在 doctrine2 集合的循环中获取当前项目的索引?我尝试了以下方法,但它 returns 总是所有项目的数量
$items = $element->getItems();
echo $items->count() // 12
foreach ($items as $item) {
echo $items->key(); // 12
}
尝试使用 indexOf
方法:
foreach ($items as $item) {
echo $items->indexOf($item); // the index
}