src/Bag.php
public function chunk($size, $preserveKeys = false)
    {
        $create = function ($items) {
            return $this->createFrom($items);
        };

        return $this->createFrom(array_map($create, array_chunk($this->items, $size, $preserveKeys)));
    }
public function chunk($size, $preserveKeys = false)
    {
        $create = function ($items) {
            return $this->createFrom($items);
        };

        return $this->createFrom(array_map($create, array_chunk($this->items, $size, $preserveKeys)));
    }
public function chunk ( $ size , $ preserveKeys = false ) { $ create = function ( $ items ) { return $ this -> createFrom ( $ items ) ; } ; return $ this -> createFrom ( array_map ( $ create , array_chunk ( $ this -> items , $ size , $ preserveKeys ) ) ) ; }
Returns a bag with the items split into chunks.

The last chunk may contain less items.

Example:

Bag::from([1, 2, 3, 4, 5])
->chunk(2);
// => Bag of [Bag of [1, 2], Bag of [3, 4], Bag of [5]]

@param int  $size         The size of each chunk
@param bool $preserveKeys When set to TRUE keys will be preserved. Default is FALSE which will reindex
the chunk numerically.

@return static|static[] Returns a multidimensional bag, with each dimension containing $size items
Returns a bag with the items split into chunks .