chuck
将集合拆分为多个指定大小的集合组。
一些示例
php
collect([1, 2, 3, 4, 5, 6, 7, 8])->chunk(4);
/**
=> Illuminate\Support\Collection {#1089
all: [
Illuminate\Support\Collection {#1091
all: [1, 2, 3, 4],
},
Illuminate\Support\Collection {#1090
all: [5, 6, 7, 8],
},
],
}
*/
php
collect([1, 2, 3, 4, 5, 6, 7, 8])->chunk(3);
/**
=> Illuminate\Support\Collection {#1088
all: [
Illuminate\Support\Collection {#1091
all: [1, 2, 3],
},
Illuminate\Support\Collection {#1090
all: [4, 5, 6],
},
Illuminate\Support\Collection {#1089
all: [7, 8],
},
],
}
*/