Well there are a few ways. Do you need to keep the array/collection intact?
Nothing is set in stone, just what ever works the easiest works for me :)
If I had to remove [0] from the array do what ever and use the altered array for the remainder that would work.
You could do something like remove the first element from the array, do what you must, then loop through the remainder.
Or you can just loop through the whole collection/array and just do a check to see if it is the first element or not.
If your using a collection the first method could be like so
$first = $collection->shift();
// do what you need with the first element
foreach($collection as $item) { // loop through the rest }
shift() will get and remove the first item from the collection.
Or you can do this, which is the approach I use.
$first = true;
foreach($items as $item)
{
if($first)
{
//modify first element
//then set first to false
$first = false;
}
else
{
//modify everything else
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community