Laravel 8 chunkWhile() {#collection-method}
2021-07-19 09:33 更新
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']]
以上内容是否对您有帮助:
更多建议: