📜  循环索引 foreach laravel - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:18.543000             🧑  作者: Mango

代码示例3
//If you are working with a collection you can do something like this:
foreach($collection as $item) {
    if($collection->last() == $item) {
        // last iteration
    }
}

//If you are working with an array (it also works with collections) you can do this:
foreach($array as $item) {
    if(end($array) == $item) {
        // last iteration
    }
}