Laravel 8 splitIn()
splitIn
方法将集合分为给定数量的组,在将其余部分分配给最终组之前,完全填充非终端组:
$collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$groups = $collection->splitIn(3);
$groups->all();
// [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]
splitIn
方法将集合分为给定数量的组,在将其余部分分配给最终组之前,完全填充非终端组:
$collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$groups = $collection->splitIn(3);
$groups->all();
// [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]