Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel foreach loop index in controller

//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
    }
}
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #Laravel #foreach #loop #index #controller
ADD COMMENT
Topic
Name
1+8 =