PHP Foreach Loop and DOMNodeList

前端 未结 2 381
一生所求
一生所求 2021-01-13 17:15

I am trying to determine the end of a foreach loop that is seeded with a collection of DOMNodeList. Currently, I am using a for loop would like to avoid having a \'magic\'

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 18:10

    $cols->length
    

    Should give you the number of items in the list

    for ($i = 0; $i < $cols->length; $i++) {
    
    // ...
    
    if ($i == $cols->length - 1) {
    // last column
    

提交回复
热议问题