Chunk() trong Laravel là gì?

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ới

Tạ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ạ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[];

02 phiên bản.

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[];

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[];

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[];

9

phươ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ết

Danh 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

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ậ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[];

19

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[];

20

use Illuminate\Support\Collection;

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

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 đã cho

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

8

use Illuminate\Support\Collection;

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

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] {

1

Phươ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] {

2

use Illuminate\Support\Collection;

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

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] {

6

use Illuminate\Support\Collection;

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

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] {

9

use Illuminate\Support\Collection;

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

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ậ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[];

3

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 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]];

0

Lư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[];

00 đặ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[];

40

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]];

1

use Illuminate\Support\Collection;

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

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]];

2

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[];

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ấ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[];

46

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]];

3

Ngoà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]];

4

Bạ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]];

5

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 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ôngContain

use Illuminate\Support\Collection;

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

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]];

6

use Illuminate\Support\Collection;

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

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

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]];

7

use Illuminate\Support\Collection;

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

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]];

8

Bạ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]];

9

use Illuminate\Support\Collection;

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

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[];

0

use Illuminate\Support\Collection;

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

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ệ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[];

1

Nế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

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 đã cho

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

2

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[];

71

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 đã cho

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

3

use Illuminate\Support\Collection;

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

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 đã cho

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

4

use Illuminate\Support\Collection;

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

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ô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[];

5

Ngoà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ô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[];

6

Bạ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ậ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[];

7

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 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

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ậ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[];

1

Nế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

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ậ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[];

9

Nế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[];

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[];

88

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

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 đó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[];

91

Nế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ì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[];

91

use Illuminate\Support\Collection;

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

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 đã cho

use Illuminate\Support\Collection;

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

Bạ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ạ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[];

94

use Illuminate\Support\Collection;

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

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 đị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[];

95

Nế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ề true

use Illuminate\Support\Collection;

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[];

99

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ỉ đị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[];

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ấ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.

use Illuminate\Support\Collection;

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

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 đị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[];

98

Nế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ó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[];

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ố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[];

906

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 đã cho

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

80

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[];

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ạ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[];

81

use Illuminate\Support\Collection;

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

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[];

82

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[];

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 ra

use Illuminate\Support\Collection;

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[];

916

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ị đã cho

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

84

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[];

917 với toán tử so sá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[];

85

Giố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[];

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[];

921

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ấ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[];

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[];

923

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ấ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[];

88

Nế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[];

924

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

89

Trong 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ẳ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[];

928

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] {

10

use Illuminate\Support\Collection;

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

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] {

11

Cảnh báo
Không giống như hầu hết các phương pháp thu thập khá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[];

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[];

933

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] {

12

use Illuminate\Support\Collection;

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

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] {

13

Bạ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] {

14

Bạ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] {

15

use Illuminate\Support\Collection;

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

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] {

16

Thay 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] {

17

Nhiề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] {

18

use Illuminate\Support\Collection;

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

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] {

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[];

943

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] {

20

use Illuminate\Support\Collection;

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

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] {

21

Nế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] {

22

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[];

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] {

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[];

948

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] {

24

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[];

951

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] {

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[];

954

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

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] {

26

use Illuminate\Support\Collection;

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

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] {

27

use Illuminate\Support\Collection;

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

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] {

28

Bạ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] {

29

use Illuminate\Support\Collection;

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

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] {

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[];

968

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] {

61

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[];

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] {

62

use Illuminate\Support\Collection;

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

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] {

64

Bằ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ậ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[];

977

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 tin

use Illuminate\Support\Collection;

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

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ậ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[];

982

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] {

65

Cảnh báo
Giống như hầu hết các phương pháp thu thập khá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 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[];

986

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] {

66

use Illuminate\Support\Collection;

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

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] {

67

use Illuminate\Support\Collection;

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

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] {

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[];

992

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] {

69

use Illuminate\Support\Collection;

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

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] {

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[];

996

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] {

91

use Illuminate\Support\Collection;

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

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] {

92

Nế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] {

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[];

800

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] {

94

use Illuminate\Support\Collection;

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

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] {

95

use Illuminate\Support\Collection;

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

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] {

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[];

806

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] {

97

Bạ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

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

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] {

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[];

813

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ô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[];

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[];

815

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ệ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[];

31

use Illuminate\Support\Collection;

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

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ạo

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

32

use Illuminate\Support\Collection;

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

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ệ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[];

33

use Illuminate\Support\Collection;

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

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 đã cho

use Illuminate\Support\Collection;

use Illuminate\Support\Str;

Collection::macro['toUpper', function [] {

return $this->map[function [$value] {

return Str::upper[$value];

$collection = collect[['first', 'second']];

$upper = $collection->toUpper[];

34

Bạ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[];

35

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 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[];

36

Nế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[];

37

use Illuminate\Support\Collection;

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

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ậ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[];

38

Bạ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ậ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[];

38

use Illuminate\Support\Collection;

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

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ậ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[];

38

Bạ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]];

01

use Illuminate\Support\Collection;

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

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]];

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[];

831

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]];

7

use Illuminate\Support\Collection;

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

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]];

04

use Illuminate\Support\Collection;

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

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]];

05

Bạ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]];

06

Nế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[];

839

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 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]];

07

use Illuminate\Support\Collection;

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

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]];

08

use Illuminate\Support\Collection;

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

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]];

09

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[];

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]];

10

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[];

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]];

11

use Illuminate\Support\Collection;

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

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]];

12

use Illuminate\Support\Collection;

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

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[];

903

use Illuminate\Support\Collection;

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

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]];

14

use Illuminate\Support\Collection;

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

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]];

15

use Illuminate\Support\Collection;

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

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]];

16

use Illuminate\Support\Collection;

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

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]];

17

Việ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]];

18

Ngoà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]];

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[];

869

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ậ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[];

38

Bạ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ậ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[];

38

use Illuminate\Support\Collection;

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

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]];

22

use Illuminate\Support\Collection;

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

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]];

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[];

876

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]];

24

Bạ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]];

25

Cả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ề

use Illuminate\Support\Collection;

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, 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[];

882

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]];

26

Cảnh báo
Nếu lệnh gọi lại không bao giờ 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, 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[];

887

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]];

27

Nế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]];

28

Theo 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ú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[];

890

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]];

30

Bạ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]];

31

use Illuminate\Support\Collection;

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

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]];

32

Bạ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]];

33

Ngoà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]];

34

Nế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

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

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]];

35

Nế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ức

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

108 và

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

109.

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

110

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]];

36

Phươ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]];

37

Ngoà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]];

38

Nế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]];

39

Khi 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

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

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]];

41

Khô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

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

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

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]];

43

Hà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

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]];

44

Bạ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]];

45

Ngoà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

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

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

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]];

49

Nế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]];

50

Ngoà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

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]];

52

Bạ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

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]];

54

Bạ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]];

55

Cả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ề

use Illuminate\Support\Collection;

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, phương thức

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

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] {

146

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]];

56

Cảnh báo
Nếu lệnh gọi lại không bao giờ 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, phương thức

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

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] {

151

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

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

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]];

59

Cảnh báo

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

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

use Illuminate\Support\Collection;

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 để thay thế.

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

162

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

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]];

61

Cảnh báo
Không giống như hầu hết các phương pháp thu thập khá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 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.

$collection = collect[['taylor', 'abigail', null]]->map[function [$name] {

}]->reject[function [$name] {

168

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

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

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]];

64

Khi 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]];

65

Cuố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]];

66

Phươ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

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

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]];

67

Cuộ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

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

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

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

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

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

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]];

72

Cuộ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

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]];

74

Lầ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

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]];

76

Lầ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

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]];

78

Phươ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 '

Chủ Đề