Category: Laravel

Since Laravel 8.16, it is possible to split a collection into chunks in two different ways. The first one, that already existed, is the split method: This method breaks a collection into a specified amount of groups. As you can see, it tries to keep the amount of items in each group as close together as possible.

What if you want to split a collection into groups of similar size, and put the remainder in the last group?

It works almost the same, except that the collection will now be split into 2 groups of sizes 3, and 1 group with the remaining item.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners