Lớp
$collection = collect[[1, 2, 3]];
99 cung cấp một trình bao bọc thuận tiện, trôi chảy để làm việc với các mảng dữ liệu. Ví dụ: kiểm tra đoạn mã sau. Chúng ta sẽ sử dụng trình trợ giúp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
00 để tạo một thể hiện bộ sưu tập mới từ mảng, chạy hàm use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
01 trên từng phần tử, sau đó xóa tất cả các phần tử trống$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Như bạn có thể thấy, lớp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 cho phép bạn xâu chuỗi các phương thức của nó để thực hiện ánh xạ trôi chảy và rút gọn mảng bên dưới. Nói chung, các bộ sưu tập là bất biến, nghĩa là mọi phương thức use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 đều trả về một thể hiện use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 hoàn toàn mớiTạo bộ sưu tập
Như đã đề cập ở trên, trình trợ giúp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
00 trả về một phiên bản $collection = collect[[1, 2, 3]];
99 mới cho mảng đã cho. Vì vậy, việc tạo một bộ sưu tập cũng đơn giản như$collection = collect[[1, 2, 3]];
Lưu ý
Kết quả của truy vấn Eloquent luôn được trả về dưới dạng02 phiên bản.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Mở rộng bộ sưu tập
Các bộ sưu tập là "có thể điều chỉnh được", cho phép bạn thêm các phương thức bổ sung vào lớp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 trong thời gian chạy. Phương thức use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
10 của lớp $collection = collect[[1, 2, 3]];
99 chấp nhận một bao đóng sẽ được thực thi khi macro của bạn được gọi. Việc đóng macro có thể truy cập các phương thức khác của bộ sưu tập thông qua use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
11, giống như thể nó là một phương thức thực sự của lớp bộ sưu tập. Ví dụ: đoạn mã sau thêm phương thức use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
12 vào lớp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Thông thường, bạn nên khai báo các macro thu thập trong phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
14 của nhà cung cấp dịch vụĐối số vĩ mô
Nếu cần, bạn có thể xác định các macro chấp nhận các đối số bổ sung
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
9phương pháp có sẵn
Đối với phần lớn các tài liệu về bộ sưu tập còn lại, chúng ta sẽ thảo luận về từng phương thức có sẵn trên lớp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02. Hãy nhớ rằng, tất cả các phương thức này có thể được xâu chuỗi để thao tác thành thạo mảng bên dưới. Hơn nữa, hầu hết mọi phương thức đều trả về một phiên bản use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 mới, cho phép bạn giữ lại bản gốc của bộ sưu tập khi cần thiếtDanh sách phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
17
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
18 trả về mảng cơ bản được đại diện bởi bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
19
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Bí danh cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
20use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
21
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
20 trả về giá trị trung bình của một khóa đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
8use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
23
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
24 chia bộ sưu tập thành nhiều bộ sưu tập nhỏ hơn có kích thước nhất định$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
1Phương pháp này đặc biệt hữu ích trong các khung nhìn khi làm việc với hệ thống lưới như Bootstrap. Ví dụ: hãy tưởng tượng bạn có một bộ sưu tập các mô hình Eloquent mà bạn muốn hiển thị dưới dạng lưới
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
2use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
25
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
26 chia bộ sưu tập thành nhiều bộ sưu tập nhỏ hơn dựa trên đánh giá của cuộc gọi lại đã cho. Biến use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
27 được truyền cho bao đóng có thể được sử dụng để kiểm tra phần tử trước đó$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
6use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
28
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
29 thu gọn một tập hợp các mảng thành một tập hợp phẳng duy nhất$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
9use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
30
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
00 trả về một phiên bản use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 mới với các mục hiện có trong bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
3Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
00 chủ yếu hữu ích để chuyển đổi các bộ sưu tập lười biếng thành các phiên bản use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 tiêu chuẩn$collection = collect[[1, 2, 3]];
0Lưu ý
Phương thức00 đặc biệt hữu ích khi bạn có một phiên bản của
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
36 và cần một phiên bản bộ sưu tập không lười biếng. Vì
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
30 là một phần của hợp đồng
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
36, nên bạn có thể yên tâm sử dụng nó để lấy phiên bản
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
40
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
41 kết hợp các giá trị của bộ sưu tập, dưới dạng khóa, với các giá trị của một mảng hoặc bộ sưu tập khác$collection = collect[[1, 2, 3]];
1use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
42
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
43 nối các giá trị của use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
44 hoặc bộ sưu tập đã cho vào phần cuối của bộ sưu tập khác$collection = collect[[1, 2, 3]];
2Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
43 lập chỉ mục lại các khóa bằng số cho các mục được nối với bộ sưu tập gốc. Để duy trì các khóa trong bộ sưu tập kết hợp, hãy xem phương pháp hợp nhấtuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
46
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47 xác định xem bộ sưu tập có chứa một mục nhất định hay không. Bạn có thể chuyển một bao đóng cho phương thức use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47 để xác định xem một phần tử có tồn tại trong bộ sưu tập khớp với một bài kiểm tra sự thật đã cho hay không$collection = collect[[1, 2, 3]];
3Ngoài ra, bạn có thể chuyển một chuỗi tới phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47 để xác định xem bộ sưu tập có chứa giá trị mục đã cho hay không$collection = collect[[1, 2, 3]];
4Bạn cũng có thể chuyển một cặp khóa/giá trị cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47, phương thức này sẽ xác định xem cặp đã cho có tồn tại trong bộ sưu tập hay không$collection = collect[[1, 2, 3]];
5Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47 sử dụng so sánh "lỏng lẻo" khi kiểm tra giá trị mục, nghĩa là một chuỗi có giá trị nguyên sẽ được coi là bằng với một số nguyên có cùng giá trị. Sử dụng phương pháp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
52 để lọc bằng cách so sánh "nghiêm ngặt"Đối với nghịch đảo của
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47, hãy xem phương thức khôngContainuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
54
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
55 xác định xem bộ sưu tập có chứa một mục hay không$collection = collect[[1, 2, 3]];
6use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
56
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức này có cùng chữ ký với phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47; Lưu ý
Hành vi của phương thức này được sửa đổi khi sử dụng Bộ sưu tập Eloquent.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
58
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
59 trả về tổng số mục trong bộ sưu tập$collection = collect[[1, 2, 3]];
7use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
60
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
61 đếm số lần xuất hiện của các giá trị trong bộ sưu tập. Theo mặc định, phương thức đếm số lần xuất hiện của mọi phần tử, cho phép bạn đếm một số "loại" phần tử nhất định trong bộ sưu tập$collection = collect[[1, 2, 3]];
8Bạn chuyển một lần đóng cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
61 để đếm tất cả các mục theo một giá trị tùy chỉnh$collection = collect[[1, 2, 3]];
9use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
63
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
64 kết hợp chéo các giá trị của tập hợp giữa các mảng hoặc tập hợp đã cho, trả về một tích Descartes với tất cả các hoán vị có thểuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
0use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
65
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
66 kết xuất các mục của bộ sưu tập và kết thúc thực thi tập lệnhuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
1Nếu bạn không muốn dừng thực thi tập lệnh, hãy sử dụng phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
67 để thay thếuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
68
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
69 so sánh bộ sưu tập với một bộ sưu tập khác hoặc một PHP use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
44 đơn giản dựa trên các giá trị của nó. Phương thức này sẽ trả về các giá trị trong bộ sưu tập ban đầu không có trong bộ sưu tập đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
2Lưu ý
Hành vi của phương thức này được sửa đổi khi sử dụng Bộ sưu tập Eloquent.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
71
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
72 so sánh bộ sưu tập với một bộ sưu tập khác hoặc một PHP use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
44 đơn giản dựa trên các khóa và giá trị của nó. Phương thức này sẽ trả về các cặp khóa/giá trị trong bộ sưu tập ban đầu không có trong bộ sưu tập đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
3use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
74
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
75 so sánh bộ sưu tập với một bộ sưu tập khác hoặc một PHP use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
44 đơn giản dựa trên các khóa của nó. Phương thức này sẽ trả về các cặp khóa/giá trị trong bộ sưu tập ban đầu không có trong bộ sưu tập đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
4use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
77
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
78 xác định xem bộ sưu tập không chứa một mục nhất định. Bạn có thể chuyển một bao đóng cho phương thức use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
78 để xác định xem một phần tử không tồn tại trong bộ sưu tập có khớp với một bài kiểm tra sự thật đã cho hay khônguse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
5Ngoài ra, bạn có thể chuyển một chuỗi tới phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
78 để xác định xem bộ sưu tập có chứa giá trị mục đã cho hay khônguse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
6Bạn cũng có thể chuyển một cặp khóa/giá trị cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
78, phương thức này sẽ xác định xem cặp đã cho không tồn tại trong bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
7Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
78 sử dụng phép so sánh "lỏng lẻo" khi kiểm tra giá trị mục, nghĩa là một chuỗi có giá trị nguyên sẽ được coi là bằng với một số nguyên có cùng giá trịuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
83
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
67 kết xuất các mục của bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
1Nếu bạn muốn ngừng thực thi tập lệnh sau khi kết xuất bộ sưu tập, hãy sử dụng phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
66 để thay thếuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
86
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
87 truy xuất và trả về các giá trị trùng lặp từ bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
9Nếu bộ sưu tập chứa các mảng hoặc đối tượng, bạn có thể chuyển khóa của các thuộc tính mà bạn muốn kiểm tra các giá trị trùng lặp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
90use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
88
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức này có cùng chữ ký với phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
87; use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
90
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
91 lặp lại các mục trong bộ sưu tập và chuyển từng mục đến một bao đónguse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
91Nếu bạn muốn ngừng lặp qua các mục, bạn có thể trả lại
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
92 từ lần đóng của mìnhuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
91use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
93
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
94 lặp lại các mục của bộ sưu tập, chuyển từng giá trị mục được lồng vào hàm gọi lại đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
93Bạn có thể ngừng lặp qua các mục bằng cách trả về
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
92 từ cuộc gọi lạiuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
94use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
96
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
97 có thể được sử dụng để xác minh rằng tất cả các phần tử của bộ sưu tập đều vượt qua một bài kiểm tra sự thật nhất địnhuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
95Nếu bộ sưu tập trống, phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
97 sẽ trả về trueuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
96use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
99
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
900 trả về tất cả các mục trong bộ sưu tập ngoại trừ những mục có khóa được chỉ địnhuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
97Đối với nghịch đảo của
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
900, hãy xem phương pháp duy nhấtLưu ý
Hành vi của phương thức này được sửa đổi khi sử dụng Bộ sưu tập Eloquent.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
902
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
903 lọc bộ sưu tập bằng cách sử dụng lệnh gọi lại đã cho, chỉ giữ lại những mục vượt qua bài kiểm tra độ tin cậy nhất địnhuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
98Nếu không cung cấp lệnh gọi lại, tất cả các mục nhập của bộ sưu tập tương đương với
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
92 sẽ bị xóause Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
99Đối với nghịch đảo của
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
903, xem phương pháp từ chốiuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
906
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
907 trả về phần tử đầu tiên trong bộ sưu tập vượt qua bài kiểm tra sự thật đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
80Bạn cũng có thể gọi phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
907 không có đối số để lấy phần tử đầu tiên trong tập hợp. Nếu bộ sưu tập trống, use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
909 được trả lạiuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
81use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
910
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
911 giống với phương pháp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
907; use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
82Bạn cũng có thể gọi phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
911 không có đối số để lấy phần tử đầu tiên trong tập hợp. Nếu bộ sưu tập trống, một ngoại lệ use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
913 sẽ được đưa rause Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
83use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
916
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
917 trả về phần tử đầu tiên trong bộ sưu tập với cặp khóa/giá trị đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
84Bạn cũng có thể gọi phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
917 với toán tử so sánhuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
85Giống như phương thức where, bạn có thể truyền một đối số cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
917. Trong trường hợp này, phương thức use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
917 sẽ trả về mục đầu tiên có giá trị của khóa mục đã cho là "trung thực"use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
86use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
921
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
922 lặp qua bộ sưu tập và chuyển từng giá trị cho bao đóng đã cho. Việc đóng cửa có thể tự do sửa đổi mục và trả lại, do đó tạo thành một bộ sưu tập mới gồm các mục đã sửa đổi. Sau đó, mảng được san bằng một cấpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
87use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
923
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
924 làm phẳng một tập hợp nhiều chiều thành một chiều duy nhấtuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
88Nếu cần, bạn có thể chuyển đối số "độ sâu" cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
924use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
89Trong ví dụ này, gọi
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
924 mà không cung cấp độ sâu cũng sẽ làm phẳng các mảng lồng nhau, dẫn đến ____1927. Cung cấp độ sâu cho phép bạn chỉ định số lượng các mảng lồng nhau sẽ được làm phẳnguse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
928
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
929 hoán đổi các khóa của bộ sưu tập với các giá trị tương ứng của chúng$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
10use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
930
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
931 xóa một mục khỏi bộ sưu tập bằng khóa của nó$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
11Cảnh báo
Không giống như hầu hết các phương pháp thu thập khác,931 không trả về một bộ sưu tập mới đã sửa đổi; .
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
933
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
934 trả về một bộ sưu tập mới chứa các mục sẽ có trên một số trang nhất định. Phương thức chấp nhận số trang làm đối số đầu tiên và số lượng mục hiển thị trên mỗi trang làm đối số thứ hai$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
12use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
935
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
936 trả về mục tại một khóa nhất định. Nếu khóa không tồn tại, use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
909 được trả về$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
13Bạn có thể tùy chọn chuyển một giá trị mặc định làm đối số thứ hai
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
14Bạn thậm chí có thể chuyển một cuộc gọi lại làm giá trị mặc định của phương thức. Kết quả của cuộc gọi lại sẽ được trả về nếu khóa được chỉ định không tồn tại
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
15use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
938
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
939 nhóm các mục của bộ sưu tập theo một khóa nhất định$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
16Thay vì chuyển một chuỗi
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
940, bạn có thể chuyển một cuộc gọi lại. Cuộc gọi lại sẽ trả về giá trị bạn muốn khóa nhóm theo$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
17Nhiều tiêu chí nhóm có thể được thông qua dưới dạng một mảng. Mỗi phần tử của mảng sẽ được áp vào mức tương ứng trong mảng nhiều chiều
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
18use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
941
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
942 xác định xem một khóa đã cho có tồn tại trong bộ sưu tập hay không$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
19use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
943
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
944 xác định xem có bất kỳ khóa nào trong số các khóa đã cho tồn tại trong bộ sưu tập hay không$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
20use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
945
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
946 kết hợp các mục trong một bộ sưu tập. Đối số của nó phụ thuộc vào loại mục trong bộ sưu tập. Nếu bộ sưu tập chứa các mảng hoặc đối tượng, bạn nên chuyển khóa của các thuộc tính mà bạn muốn tham gia và chuỗi "keo" mà bạn muốn đặt giữa các giá trị$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
21Nếu bộ sưu tập chứa các chuỗi đơn giản hoặc giá trị số, bạn nên chuyển "keo" làm đối số duy nhất cho phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
22Bạn có thể chuyển một bao đóng cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
946 nếu bạn muốn định dạng các giá trị được ẩn$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
23use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
948
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
949 loại bỏ bất kỳ giá trị nào khỏi bộ sưu tập ban đầu không có trong use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
44 hoặc bộ sưu tập đã cho. Bộ sưu tập kết quả sẽ bảo toàn các khóa của bộ sưu tập gốc$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
24Lưu ý
Hành vi của phương thức này được sửa đổi khi sử dụng Bộ sưu tập Eloquent.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
951
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
952 loại bỏ bất kỳ khóa nào và các giá trị tương ứng của chúng khỏi bộ sưu tập ban đầu không có trong use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
44 hoặc bộ sưu tập đã cho$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
25use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
954
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
955 trả về use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956 nếu bộ sưu tập trống; use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
958
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
959 trả về use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956 nếu bộ sưu tập không trống; $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
26use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
962
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
963 kết hợp các giá trị của bộ sưu tập với một chuỗi. Sử dụng đối số thứ hai của phương thức này, bạn cũng có thể chỉ định cách thêm phần tử cuối cùng vào chuỗi$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
27use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
964
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
965 khóa bộ sưu tập theo khóa đã cho. Nếu nhiều mục có cùng khóa, chỉ mục cuối cùng sẽ xuất hiện trong bộ sưu tập mới$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
28Bạn cũng có thể chuyển một cuộc gọi lại cho phương thức. Cuộc gọi lại sẽ trả về giá trị để khóa bộ sưu tập theo
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
29use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
966
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
967 trả về tất cả các khóa của bộ sưu tập$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
60use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
968
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
969 trả về phần tử cuối cùng trong bộ sưu tập vượt qua bài kiểm tra sự thật đã cho$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
61Bạn cũng có thể gọi phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
969 không có đối số để lấy phần tử cuối cùng trong tập hợp. Nếu bộ sưu tập trống, use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
909 được trả lại$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
62use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
972
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
973 trả về một thể hiện use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
974 mới từ mảng các mục bên dưới$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
63Điều này đặc biệt hữu ích khi bạn cần thực hiện các phép biến đổi trên một
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 khổng lồ chứa nhiều mục$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
64Bằng cách chuyển đổi bộ sưu tập thành
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
974, chúng tôi tránh phải phân bổ nhiều bộ nhớ bổ sung. Mặc dù bộ sưu tập ban đầu vẫn giữ các giá trị của nó trong bộ nhớ, các bộ lọc tiếp theo sẽ không. Do đó, hầu như không có bộ nhớ bổ sung nào được phân bổ khi lọc kết quả của bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
977
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức tĩnh
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
10 cho phép bạn thêm các phương thức vào lớp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
02 trong thời gian chạy. Tham khảo tài liệu về mở rộng bộ sưu tập để biết thêm thông tinuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
980
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức tĩnh
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
981 tạo một thể hiện bộ sưu tập mới. Xem phần Tạo bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
982
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
983 lặp qua bộ sưu tập và chuyển từng giá trị cho cuộc gọi lại đã cho. Cuộc gọi lại có thể tự do sửa đổi mục và trả lại mục đó, do đó tạo thành một bộ sưu tập mới gồm các mục đã sửa đổi$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
65Cảnh báo
Giống như hầu hết các phương pháp thu thập khác,983 trả về một phiên bản thu thập mới; . Nếu bạn muốn chuyển đổi bộ sưu tập ban đầu, hãy sử dụng phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
985.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
986
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
986 lặp lại bộ sưu tập, tạo một thể hiện mới của lớp đã cho bằng cách chuyển giá trị vào hàm tạo$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
66use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
988
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
989 lặp lại các mục của bộ sưu tập, chuyển từng giá trị mục lồng nhau vào bao đóng đã cho. Việc đóng cửa có thể tự do sửa đổi mục và trả lại, do đó tạo thành một bộ sưu tập mới gồm các mục đã sửa đổi$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
67use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
990
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
991 nhóm các mục của bộ sưu tập theo bao đóng đã cho. Việc đóng sẽ trả về một mảng kết hợp chứa một cặp khóa/giá trị duy nhất, do đó tạo thành một tập hợp các giá trị được nhóm mới$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
68use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
992
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
993 lặp qua bộ sưu tập và chuyển từng giá trị cho cuộc gọi lại đã cho. Cuộc gọi lại sẽ trả về một mảng kết hợp chứa một cặp khóa/giá trị$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
69use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
994
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
995 trả về giá trị lớn nhất của một khóa đã cho$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
90use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
996
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
997 trả về giá trị trung bình của một khóa đã cho$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
91use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
998
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
999 hợp nhất mảng hoặc bộ sưu tập đã cho với bộ sưu tập ban đầu. Nếu khóa chuỗi trong các mục nhất định khớp với khóa chuỗi trong bộ sưu tập ban đầu, thì giá trị của mục đã cho sẽ ghi đè lên giá trị trong bộ sưu tập ban đầu$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
92Nếu các khóa của mục nhất định là số, các giá trị sẽ được thêm vào cuối bộ sưu tập
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
93use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
800
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
801 kết hợp đệ quy mảng hoặc bộ sưu tập đã cho với bộ sưu tập ban đầu. Nếu một khóa chuỗi trong các mục đã cho khớp với một khóa chuỗi trong bộ sưu tập ban đầu, thì các giá trị cho các khóa này sẽ được hợp nhất với nhau thành một mảng và điều này được thực hiện theo cách đệ quy$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
94use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
802
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
803 trả về giá trị tối thiểu của một khóa đã cho$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
95use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
804
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
805 trả về giá trị chế độ của một khóa đã cho$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
96use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
806
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
807 tạo một bộ sưu tập mới bao gồm mọi phần tử thứ n$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
97Bạn có thể tùy ý chuyển phần bù bắt đầu làm đối số thứ hai
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
808
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
809 trả về các mục trong bộ sưu tập với các khóa được chỉ định$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
98Đối với nghịch đảo của
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
809, hãy xem phương pháp ngoại trừLưu ý
Hành vi của phương thức này được sửa đổi khi sử dụng Bộ sưu tập Eloquent.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
811
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
812 sẽ điền vào mảng với giá trị đã cho cho đến khi mảng đạt đến kích thước đã chỉ định. Phương thức này hoạt động giống như hàm Array_pad PHPĐể đệm sang trái, bạn nên chỉ định kích thước âm. Sẽ không có phần đệm nào diễn ra nếu giá trị tuyệt đối của kích thước đã cho nhỏ hơn hoặc bằng độ dài của mảng
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
99use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
813
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
814 có thể được kết hợp với việc phá hủy mảng PHP để phân tách các phần tử vượt qua bài kiểm tra sự thật nhất định khỏi những phần tử khônguse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
30use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
815
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
816 chuyển bộ sưu tập tới bao đóng đã cho và trả về kết quả của bao đóng đã thực hiệnuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
31use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
817
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
818 tạo một thể hiện mới của lớp đã cho và chuyển bộ sưu tập vào hàm tạouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
32use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
819
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
820 chuyển bộ sưu tập tới mảng các lần đóng đã cho và trả về kết quả của các lần đóng đã thực hiệnuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
33use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
821
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
822 truy xuất tất cả các giá trị cho một khóa đã chouse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
34Bạn cũng có thể chỉ định cách bạn muốn bộ sưu tập kết quả được khóa
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
35Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
822 cũng hỗ trợ truy xuất các giá trị lồng nhau bằng cách sử dụng ký hiệu "dấu chấm"use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
36Nếu tồn tại các khóa trùng lặp, phần tử phù hợp cuối cùng sẽ được chèn vào bộ sưu tập đã chọn
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
37use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
824
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
825 loại bỏ và trả về mục cuối cùng từ bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
38Bạn có thể chuyển một số nguyên cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
825 để xóa và trả lại nhiều mục từ phần cuối của bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
38use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
827
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
828 thêm một mục vào đầu bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
38Bạn cũng có thể chuyển đối số thứ hai để chỉ định khóa của mục được thêm vào trước
$collection = collect[[1, 2, 3]];
01use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
829
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
830 loại bỏ và trả về một mục từ bộ sưu tập bằng khóa của nó$collection = collect[[1, 2, 3]];
02use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
831
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
832 nối thêm một mục vào cuối bộ sưu tập$collection = collect[[1, 2, 3]];
7use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
833
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
834 đặt khóa và giá trị đã cho trong bộ sưu tập$collection = collect[[1, 2, 3]];
04use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
835
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
836 trả về một mục ngẫu nhiên từ bộ sưu tập$collection = collect[[1, 2, 3]];
05Bạn có thể chuyển một số nguyên tới
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
836 để chỉ định số lượng mục bạn muốn truy xuất ngẫu nhiên. Một bộ sưu tập các mặt hàng luôn được trả về khi chuyển rõ ràng số lượng mặt hàng bạn muốn nhận$collection = collect[[1, 2, 3]];
06Nếu thể hiện bộ sưu tập có ít mục hơn so với yêu cầu, phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
836 sẽ đưa ra một use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
839Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
836 cũng chấp nhận một bao đóng, sẽ nhận thể hiện bộ sưu tập hiện tại$collection = collect[[1, 2, 3]];
07use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
841
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
842 trả về một tập hợp chứa các số nguyên nằm trong phạm vi đã chỉ định$collection = collect[[1, 2, 3]];
08use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
843
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
844 giảm bộ sưu tập thành một giá trị duy nhất, chuyển kết quả của mỗi lần lặp vào lần lặp tiếp theo$collection = collect[[1, 2, 3]];
09Giá trị của
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
845 trong lần lặp đầu tiên là use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
909; $collection = collect[[1, 2, 3]];
10Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
844 cũng chuyển các khóa mảng trong các bộ sưu tập kết hợp tới hàm gọi lại đã cho$collection = collect[[1, 2, 3]];
11use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
849
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
850 rút gọn bộ sưu tập thành một mảng giá trị, chuyển kết quả của mỗi lần lặp vào lần lặp tiếp theo. Phương pháp này tương tự như phương pháp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
844; $collection = collect[[1, 2, 3]];
12use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
852
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
853 lọc bộ sưu tập bằng cách sử dụng bao đóng đã cho. Việc đóng sẽ trả về use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956 nếu mục này sẽ bị xóa khỏi bộ sưu tập kết quả$collection = collect[[1, 2, 3]];
13Đối với nghịch đảo của phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
853, xem phương pháp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
903use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
857
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
858 hoạt động tương tự như use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
999; $collection = collect[[1, 2, 3]];
14use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
861
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức này hoạt động giống như
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
858, nhưng nó sẽ lặp lại thành các mảng và áp dụng quy trình thay thế tương tự cho các giá trị bên trong$collection = collect[[1, 2, 3]];
15use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
863
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
864 đảo ngược thứ tự các mục của bộ sưu tập, giữ nguyên các khóa ban đầu$collection = collect[[1, 2, 3]];
16use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
865
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
866 tìm kiếm bộ sưu tập cho giá trị đã cho và trả về khóa của nó nếu tìm thấy. Nếu không tìm thấy hàng, use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
92 được trả lại$collection = collect[[1, 2, 3]];
17Việc tìm kiếm được thực hiện bằng cách so sánh "lỏng lẻo", nghĩa là một chuỗi có giá trị nguyên sẽ được coi là bằng một số nguyên có cùng giá trị. Để sử dụng phép so sánh "nghiêm ngặt", hãy chuyển
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956 làm đối số thứ hai cho phương thức$collection = collect[[1, 2, 3]];
18Ngoài ra, bạn có thể cung cấp cách đóng của riêng mình để tìm kiếm mục đầu tiên vượt qua bài kiểm tra độ tin cậy nhất định
$collection = collect[[1, 2, 3]];
19use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
869
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
870 loại bỏ và trả về mục đầu tiên từ bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
38Bạn có thể chuyển một số nguyên cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
870 để xóa và trả lại nhiều mục từ đầu bộ sưu tậpuse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
38use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
872
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
873 xáo trộn ngẫu nhiên các mục trong bộ sưu tập$collection = collect[[1, 2, 3]];
22use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
874
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
875 trả về một bộ sưu tập mới, với số phần tử đã cho bị xóa khỏi phần đầu của bộ sưu tập$collection = collect[[1, 2, 3]];
23use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
876
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
877 bỏ qua các mục từ bộ sưu tập cho đến khi hàm gọi lại đã cho trả về use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956 và sau đó trả về các mục còn lại trong bộ sưu tập dưới dạng phiên bản bộ sưu tập mới$collection = collect[[1, 2, 3]];
24Bạn cũng có thể chuyển một giá trị đơn giản cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
877 để bỏ qua tất cả các mục cho đến khi tìm thấy giá trị đã cho$collection = collect[[1, 2, 3]];
25Cảnh báo
Nếu không tìm thấy giá trị đã cho hoặc hàm gọi lại không bao giờ trả về956, phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
877 sẽ trả về một bộ sưu tập trống.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
882
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
883 bỏ qua các mục từ bộ sưu tập trong khi hàm gọi lại đã cho trả về use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956 và sau đó trả về các mục còn lại trong bộ sưu tập dưới dạng một bộ sưu tập mới$collection = collect[[1, 2, 3]];
26Cảnh báo
Nếu lệnh gọi lại không bao giờ trả về92, phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
883 sẽ trả về một bộ sưu tập trống.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
887
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
888 trả về một phần của bộ sưu tập bắt đầu từ chỉ mục đã cho$collection = collect[[1, 2, 3]];
27Nếu bạn muốn giới hạn kích thước của lát cắt được trả về, hãy chuyển kích thước mong muốn làm đối số thứ hai cho phương thức
$collection = collect[[1, 2, 3]];
28Theo mặc định, lát cắt được trả về sẽ giữ nguyên các khóa. Nếu bạn không muốn giữ lại các khóa ban đầu, bạn có thể sử dụng phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
889 để lập chỉ mục lại chúnguse Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
890
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
891 trả về một tập hợp các khối mới biểu thị chế độ xem "cửa sổ trượt" của các mục trong bộ sưu tập$collection = collect[[1, 2, 3]];
29Điều này đặc biệt hữu ích khi kết hợp với phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
94$collection = collect[[1, 2, 3]];
30Bạn có thể tùy chọn chuyển giá trị "bước" thứ hai, giá trị này xác định khoảng cách giữa mục đầu tiên của mỗi đoạn
$collection = collect[[1, 2, 3]];
31use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
893
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
894 trả về phần tử đầu tiên trong bộ sưu tập vượt qua bài kiểm tra giá trị thực nhất định, nhưng chỉ khi bài kiểm tra giá trị thực khớp với chính xác một phần tử$collection = collect[[1, 2, 3]];
32Bạn cũng có thể chuyển một cặp khóa/giá trị cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
894, phương thức này sẽ trả về phần tử đầu tiên trong bộ sưu tập khớp với cặp đã cho, nhưng chỉ khi nó khớp chính xác với một phần tử$collection = collect[[1, 2, 3]];
33Ngoài ra, bạn cũng có thể gọi phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
894 không có đối số để lấy phần tử đầu tiên trong tập hợp nếu chỉ có một phần tử$collection = collect[[1, 2, 3]];
34Nếu không có phần tử nào trong bộ sưu tập cần được trả về bằng phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
894, một ngoại lệ use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
898 sẽ được đưa ra. Nếu có nhiều hơn một phần tử cần được trả về, một use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
899 sẽ được ném ra$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
100
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Bí danh cho phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
47$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
102
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương pháp
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
103 sắp xếp bộ sưu tập. Bộ sưu tập được sắp xếp giữ các khóa mảng ban đầu, vì vậy trong ví dụ sau, chúng tôi sẽ sử dụng phương pháp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
889 để đặt lại các khóa thành các chỉ mục được đánh số liên tiếp$collection = collect[[1, 2, 3]];
35Nếu nhu cầu sắp xếp của bạn nâng cao hơn, bạn có thể chuyển một cuộc gọi lại tới
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
103 bằng thuật toán của riêng bạn. Tham khảo tài liệu PHP trên $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
106, đây là cách gọi phương thức $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
103 của bộ sưu tập sử dụng nội bộLưu ý
Nếu bạn cần sắp xếp một tập hợp các mảng hoặc đối tượng lồng nhau, hãy xem các phương thức108 và
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
109.
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
110
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
108 sắp xếp bộ sưu tập theo khóa đã cho. Bộ sưu tập được sắp xếp giữ các khóa mảng ban đầu, vì vậy trong ví dụ sau, chúng tôi sẽ sử dụng phương pháp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
889 để đặt lại các khóa thành các chỉ mục được đánh số liên tiếp$collection = collect[[1, 2, 3]];
36Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
108 chấp nhận các cờ sắp xếp làm đối số thứ hai của nó$collection = collect[[1, 2, 3]];
37Ngoài ra, bạn có thể chuyển bao đóng của riêng mình để xác định cách sắp xếp các giá trị của bộ sưu tập
$collection = collect[[1, 2, 3]];
38Nếu bạn muốn sắp xếp bộ sưu tập của mình theo nhiều thuộc tính, bạn có thể chuyển một mảng các thao tác sắp xếp cho phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
108. Mỗi thao tác sắp xếp phải là một mảng bao gồm thuộc tính mà bạn muốn sắp xếp theo và hướng sắp xếp mong muốn$collection = collect[[1, 2, 3]];
39Khi sắp xếp một bộ sưu tập theo nhiều thuộc tính, bạn cũng có thể cung cấp các bao đóng xác định từng thao tác sắp xếp
$collection = collect[[1, 2, 3]];
40$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
115
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức này có cùng chữ ký với phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
108, nhưng sẽ sắp xếp bộ sưu tập theo thứ tự ngược lại$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
117
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức này sẽ sắp xếp bộ sưu tập theo thứ tự ngược lại với phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
103$collection = collect[[1, 2, 3]];
41Không giống như
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
103, bạn không được chuyển lệnh đóng cho $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
120. Thay vào đó, bạn nên sử dụng phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
103 và đảo ngược phép so sánh của mình$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
122
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
123 sắp xếp bộ sưu tập theo các khóa của mảng kết hợp cơ bản$collection = collect[[1, 2, 3]];
42$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
124
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức này có cùng chữ ký với phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
123, nhưng sẽ sắp xếp bộ sưu tập theo thứ tự ngược lại$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
126
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
127 sắp xếp bộ sưu tập theo các khóa của mảng kết hợp cơ bản bằng cách sử dụng hàm gọi lại$collection = collect[[1, 2, 3]];
43Hàm gọi lại phải là một hàm so sánh trả về một số nguyên nhỏ hơn, bằng hoặc lớn hơn 0. Để biết thêm thông tin, hãy tham khảo tài liệu PHP trên
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
128, đây là hàm PHP mà phương thức $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
127 sử dụng nội bộ$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
130
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
131 xóa và trả về một lát mục bắt đầu từ chỉ mục đã chỉ định$collection = collect[[1, 2, 3]];
44Bạn có thể chuyển đối số thứ hai để giới hạn kích thước của bộ sưu tập kết quả
$collection = collect[[1, 2, 3]];
45Ngoài ra, bạn có thể chuyển đối số thứ ba chứa các mục mới để thay thế các mục đã bị xóa khỏi bộ sưu tập
$collection = collect[[1, 2, 3]];
46$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
132
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
133 chia một bộ sưu tập thành một số nhóm nhất định$collection = collect[[1, 2, 3]];
47$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
134
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
135 chia một tập hợp thành một số nhóm nhất định, lấp đầy hoàn toàn các nhóm không đầu cuối trước khi phân bổ phần còn lại cho nhóm cuối cùng$collection = collect[[1, 2, 3]];
48$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
136
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
137 trả về tổng của tất cả các mục trong bộ sưu tập$collection = collect[[1, 2, 3]];
49Nếu bộ sưu tập chứa các mảng hoặc đối tượng lồng nhau, bạn nên chuyển một khóa sẽ được sử dụng để xác định giá trị nào cần tính tổng
$collection = collect[[1, 2, 3]];
50Ngoài ra, bạn có thể chuyển bao đóng của riêng mình để xác định giá trị nào của bộ sưu tập sẽ tính tổng
$collection = collect[[1, 2, 3]];
51$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
138
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
139 trả về một bộ sưu tập mới với số lượng mục được chỉ định$collection = collect[[1, 2, 3]];
52Bạn cũng có thể chuyển một số nguyên âm để lấy số mục đã chỉ định từ cuối bộ sưu tập
$collection = collect[[1, 2, 3]];
53$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
140
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
141 trả về các mục trong bộ sưu tập cho đến khi hàm gọi lại đã cho trả về use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956$collection = collect[[1, 2, 3]];
54Bạn cũng có thể chuyển một giá trị đơn giản cho phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
141 để lấy các mục cho đến khi tìm thấy giá trị đã cho$collection = collect[[1, 2, 3]];
55Cảnh báo
Nếu không tìm thấy giá trị đã cho hoặc lệnh gọi lại không bao giờ trả về956, phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
141 sẽ trả về tất cả các mục trong bộ sưu tập.
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
146
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
147 trả về các mục trong bộ sưu tập cho đến khi hàm gọi lại đã cho trả về use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
92$collection = collect[[1, 2, 3]];
56Cảnh báo
Nếu lệnh gọi lại không bao giờ trả về92, phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
147 sẽ trả về tất cả các mục trong bộ sưu tập.
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
151
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
152 chuyển bộ sưu tập tới lệnh gọi lại đã cho, cho phép bạn "chạm" vào bộ sưu tập tại một điểm cụ thể và thực hiện điều gì đó với các mục trong khi không ảnh hưởng đến chính bộ sưu tập đó. Bộ sưu tập sau đó được trả về bằng phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
152$collection = collect[[1, 2, 3]];
57$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
154
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức tĩnh
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
155 tạo một bộ sưu tập mới bằng cách gọi bao đóng đã cho một số lần được chỉ định$collection = collect[[1, 2, 3]];
58$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
156
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
157 chuyển đổi bộ sưu tập thành một PHP use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
44 đơn giản. Nếu các giá trị của bộ sưu tập là các mô hình Eloquent, thì các mô hình đó cũng sẽ được chuyển thành mảng$collection = collect[[1, 2, 3]];
59Cảnh báo
157 cũng chuyển đổi tất cả các đối tượng lồng nhau của bộ sưu tập là một thể hiện của
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
160 thành một mảng. Nếu bạn muốn lấy mảng thô bên dưới bộ sưu tập, hãy sử dụng phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
18 để thay thế.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
162
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
163 chuyển đổi bộ sưu tập thành một chuỗi được tuần tự hóa JSON$collection = collect[[1, 2, 3]];
60$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
164
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
985 lặp lại bộ sưu tập và gọi hàm gọi lại đã cho với từng mục trong bộ sưu tập. Các mục trong bộ sưu tập sẽ được thay thế bằng các giá trị được trả về bởi lệnh gọi lại$collection = collect[[1, 2, 3]];
61Cảnh báo
Không giống như hầu hết các phương pháp thu thập khác,985 tự sửa đổi bộ sưu tập. Thay vào đó, nếu bạn muốn tạo một bộ sưu tập mới, hãy sử dụng phương pháp
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
983.
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
168
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
169 mở rộng tập hợp một chiều sử dụng ký hiệu "dấu chấm" thành tập hợp đa chiều$collection = collect[[1, 2, 3]];
62$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
170
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
171 thêm mảng đã cho vào bộ sưu tập. Nếu mảng đã cho chứa các khóa đã có trong bộ sưu tập ban đầu, thì các giá trị của bộ sưu tập ban đầu sẽ được ưu tiên$collection = collect[[1, 2, 3]];
63$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
172
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
173 trả về tất cả các mục duy nhất trong bộ sưu tập. Bộ sưu tập được trả về giữ các khóa mảng ban đầu, vì vậy trong ví dụ sau, chúng tôi sẽ sử dụng phương pháp use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
889 để đặt lại các khóa thành các chỉ mục được đánh số liên tiếp$collection = collect[[1, 2, 3]];
64Khi xử lý các mảng hoặc đối tượng lồng nhau, bạn có thể chỉ định khóa được sử dụng để xác định tính duy nhất
$collection = collect[[1, 2, 3]];
65Cuối cùng, bạn cũng có thể chuyển bao đóng của riêng mình cho phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
173 để chỉ định giá trị nào sẽ xác định tính duy nhất của một mục$collection = collect[[1, 2, 3]];
66Phương pháp
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
173 sử dụng so sánh "lỏng lẻo" khi kiểm tra giá trị mục, nghĩa là một chuỗi có giá trị nguyên sẽ được coi là bằng với một số nguyên có cùng giá trị. Sử dụng phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
177 để lọc bằng cách so sánh "nghiêm ngặt"Lưu ý
Hành vi của phương thức này được sửa đổi khi sử dụng Bộ sưu tập Eloquent.
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
178
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức này có cùng chữ ký với phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
173; $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
180
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
181 sẽ thực hiện lệnh gọi lại đã cho trừ khi đối số đầu tiên được cung cấp cho phương thức ước tính là use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956$collection = collect[[1, 2, 3]];
67Cuộc gọi lại thứ hai có thể được chuyển đến phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
181. Cuộc gọi lại thứ hai sẽ được thực thi khi đối số đầu tiên được cung cấp cho phương thức $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
181 đánh giá là use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956$collection = collect[[1, 2, 3]];
68Đối với nghịch đảo của
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
181, xem phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
187$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
188
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Bí danh cho phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
189$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
190
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Bí danh cho phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
191$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
192
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức tĩnh
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
193 trả về các mục cơ bản của bộ sưu tập từ giá trị đã cho khi áp dụng$collection = collect[[1, 2, 3]];
69$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
194
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
195 lấy một giá trị đã cho từ phần tử đầu tiên của tập hợp$collection = collect[[1, 2, 3]];
70$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
196
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
889 trả về một bộ sưu tập mới với các khóa được đặt lại thành các số nguyên liên tiếp$collection = collect[[1, 2, 3]];
71$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
198
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
187 sẽ thực hiện lệnh gọi lại đã cho khi đối số đầu tiên được cung cấp cho phương thức ước tính là use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
956. Thể hiện bộ sưu tập và đối số đầu tiên được cung cấp cho phương thức $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
187 sẽ được cung cấp cho phương thức đóng$collection = collect[[1, 2, 3]];
72Cuộc gọi lại thứ hai có thể được chuyển đến phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
187. Cuộc gọi lại thứ hai sẽ được thực thi khi đối số đầu tiên được cung cấp cho phương thức $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
187 đánh giá là use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Collection::macro['toUpper', function [] {
return $this->map[function [$value] {
return Str::upper[$value];
$collection = collect[['first', 'second']];
$upper = $collection->toUpper[];
92$collection = collect[[1, 2, 3]];
73Đối với nghịch đảo của
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
187, hãy xem phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
181$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
207
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
191 sẽ thực hiện lệnh gọi lại đã cho khi bộ sưu tập trống$collection = collect[[1, 2, 3]];
74Lần đóng thứ hai có thể được chuyển đến phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
191 sẽ được thực thi khi bộ sưu tập không trống$collection = collect[[1, 2, 3]];
75Đối với nghịch đảo của
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
191, xem phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
189$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
212
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
189 sẽ thực hiện lệnh gọi lại đã cho khi bộ sưu tập không trống$collection = collect[[1, 2, 3]];
76Lần đóng thứ hai có thể được chuyển đến phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
189 sẽ được thực thi khi bộ sưu tập trống$collection = collect[[1, 2, 3]];
77Đối với nghịch đảo của
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
189, xem phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
191$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
217
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
218 lọc bộ sưu tập theo một cặp khóa/giá trị nhất định$collection = collect[[1, 2, 3]];
78Phương thức
$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
218 sử dụng so sánh "lỏng lẻo" khi kiểm tra giá trị mục, nghĩa là một chuỗi có giá trị nguyên sẽ được coi là bằng với một số nguyên có cùng giá trị. Sử dụng phương pháp $collection = collect[['taylor', 'abigail', null]]->map[function [$name] {
}]->reject[function [$name] {
220 để lọc bằng cách so sánh "nghiêm ngặt"Optionally, you may pass a comparison operator as the second parameter. Supported operators are: '===', '!==', '!=', '==', '=', '', '>', '=', and '