Answers for "loop index foreach laravel"

PHP
2

loop index foreach laravel

@foreach ($teams as $key => $team)
{{ str_ordinal($key + 1) }}
@endforeach
Posted by: Guest on February-07-2021
1

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
    }
}
Posted by: Guest on June-11-2021
0

foreach in laravel

foreach ($users as $user) {
    // stuff here
}
Posted by: Guest on March-30-2020

Browse Popular Code Answers by Language