Laravel 8 chunkWhile() {#collection-method}
chunkWhile
方法根据指定的回调值把集合分解成多个更小的集合:
$collection = collect(str_split('AABBCCCD'));
$chunks = $collection->chunkWhile(function ($current, $key, $chunk) {
return $current === $chunk->last();
});
$chunks->all();
// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]