Php array rata-rata dengan kunci

Umumnya, klausa GROUP BY dan fungsi SUM() digunakan dalam database untuk mengurutkan catatan. Grup pernyataan GROUP BY merekam dengan nilai yang sama dan mengembalikan rekaman yang difilter. SUM() adalah fungsi agregat yang digunakan oleh pernyataan GROUP BY. Operasi GROUP BY dan SUM dapat diintegrasikan ke dalam daftar data pada level kode di PHP

Gunakan fungsi PHP array_reduce() untuk GROUP BY dan SUM nilai array di PHP. Dalam contoh ini, kami akan menunjukkan cara mengelompokkan array berdasarkan kunci dan menjumlahkan nilai menggunakan PHP. Ini membantu untuk menjumlahkan nilai array dengan kunci yang sama di PHP

Dalam cuplikan kode berikut, kami akan mengelompokkan array berdasarkan category_id dan menjumlahkan nilai score dengan PHP

Kelas

$collection = collect([1, 2, 3]);

99 menyediakan pembungkus yang lancar dan nyaman untuk bekerja dengan array data. Misalnya, periksa kode berikut. Kami akan menggunakan pembantu

use Illuminate\Support\Collection;

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 untuk membuat instance koleksi baru dari array, menjalankan fungsi

use Illuminate\Support\Collection;

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 pada setiap elemen, lalu menghapus semua elemen kosong

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

})->reject(function ($name) {

Seperti yang Anda lihat, kelas

use Illuminate\Support\Collection;

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 memungkinkan Anda untuk merangkai metodenya untuk melakukan pemetaan dan pengurangan yang lancar dari array yang mendasarinya. Secara umum, koleksi tidak dapat diubah, artinya setiap metode

use Illuminate\Support\Collection;

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

use Illuminate\Support\Collection;

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 yang sama sekali baru

Membuat Koleksi

Seperti disebutkan di atas, helper

use Illuminate\Support\Collection;

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 mengembalikan instance ________0______99 baru untuk array yang diberikan. Jadi, membuat koleksi sesederhana itu

$collection = collect([1, 2, 3]);

Catatan
Hasil kueri Eloquent selalu dikembalikan sebagai

use Illuminate\Support\Collection;

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 contoh

Memperluas Koleksi

Koleksi bersifat "macroable", yang memungkinkan Anda untuk menambahkan metode tambahan ke kelas

use Illuminate\Support\Collection;

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 pada waktu proses. Metode

$collection = collect([1, 2, 3]);

99 class '

use Illuminate\Support\Collection;

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 menerima penutupan yang akan dieksekusi saat makro Anda dipanggil. Penutupan makro dapat mengakses metode koleksi lainnya melalui

use Illuminate\Support\Collection;

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, seolah-olah itu adalah metode nyata dari kelas koleksi. Misalnya, kode berikut menambahkan metode

use Illuminate\Support\Collection;

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

use Illuminate\Support\Collection;

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();

_

Biasanya, Anda harus mendeklarasikan makro pengumpulan dalam metode

use Illuminate\Support\Collection;

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 dari penyedia layanan

Argumen Makro

Jika perlu, Anda dapat menentukan makro yang menerima argumen tambahan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

Metode yang Tersedia

Untuk sebagian besar dokumentasi koleksi yang tersisa, kita akan membahas setiap metode yang tersedia di kelas

use Illuminate\Support\Collection;

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. Ingat, semua metode ini dapat dirangkai untuk memanipulasi array yang mendasarinya dengan lancar. Selain itu, hampir setiap metode mengembalikan instance

use Illuminate\Support\Collection;

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 baru, memungkinkan Anda menyimpan salinan asli koleksi bila diperlukan

Daftar Metode

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 mengembalikan array yang mendasari yang diwakili oleh koleksi

use Illuminate\Support\Collection;

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

Alias ​​untuk metode

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 mengembalikan nilai rata-rata dari kunci yang diberikan

$average = collect([1, 1, 2, 4])->avg();

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 memecah koleksi menjadi beberapa koleksi yang lebih kecil dengan ukuran tertentu

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

Metode ini sangat berguna dalam tampilan saat bekerja dengan sistem grid seperti Bootstrap. Misalnya, bayangkan Anda memiliki koleksi model Eloquent yang ingin ditampilkan dalam kisi

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 memecah koleksi menjadi beberapa koleksi yang lebih kecil berdasarkan evaluasi callback yang diberikan. Variabel

use Illuminate\Support\Collection;

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 diteruskan ke penutupan dapat digunakan untuk memeriksa elemen sebelumnya

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 menciutkan kumpulan array menjadi satu kumpulan datar

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 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

Metode

use Illuminate\Support\Collection;

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

use Illuminate\Support\Collection;

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 baru dengan item yang saat ini ada dalam koleksi

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

Metode

use Illuminate\Support\Collection;

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 terutama berguna untuk mengonversi ke instance

use Illuminate\Support\Collection;

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 standar

$collection = collect([1, 2, 3]);

0

Catatan
Metode

use Illuminate\Support\Collection;

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 sangat berguna ketika Anda memiliki instance

use Illuminate\Support\Collection;

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 dan membutuhkan instance koleksi yang tidak malas. Karena

use Illuminate\Support\Collection;

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 adalah bagian dari kontrak

use Illuminate\Support\Collection;

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, Anda dapat menggunakannya dengan aman untuk mendapatkan instance

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 menggabungkan nilai koleksi, sebagai kunci, dengan nilai array atau koleksi lain

$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

Metode

use Illuminate\Support\Collection;

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 menambahkan

use Illuminate\Support\Collection;

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 atau nilai koleksi yang diberikan ke akhir koleksi lain

$collection = collect([1, 2, 3]);

_2

Metode

use Illuminate\Support\Collection;

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 secara numerik mengindeks ulang kunci untuk item yang digabungkan ke koleksi asli. Untuk mempertahankan kunci dalam koleksi asosiatif, lihat metodenya

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 menentukan apakah koleksi berisi item tertentu. Anda dapat melewati penutupan metode

use Illuminate\Support\Collection;

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 untuk menentukan apakah ada elemen dalam koleksi yang cocok dengan uji kebenaran yang diberikan

$collection = collect([1, 2, 3]);

_3

Alternatifnya, Anda dapat meneruskan string ke metode

use Illuminate\Support\Collection;

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 untuk menentukan apakah koleksi berisi nilai item yang diberikan

$collection = collect([1, 2, 3]);

_4

Anda juga dapat meneruskan pasangan kunci/nilai ke metode

use Illuminate\Support\Collection;

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, yang akan menentukan apakah pasangan yang diberikan ada dalam koleksi

$collection = collect([1, 2, 3]);

5

Metode

use Illuminate\Support\Collection;

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 menggunakan perbandingan "longgar" saat memeriksa nilai item, artinya string dengan nilai bilangan bulat akan dianggap sama dengan bilangan bulat dengan nilai yang sama. Gunakan metode untuk memfilter menggunakan perbandingan "ketat".

Untuk kebalikan dari

use Illuminate\Support\Collection;

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, lihat metodenya

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 menentukan apakah koleksi berisi satu item

$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

Metode ini memiliki tanda tangan yang sama dengan metode;

Catatan
Perilaku metode ini diubah saat menggunakan

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 mengembalikan jumlah item dalam koleksi

$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

Metode

use Illuminate\Support\Collection;

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 menghitung kemunculan nilai dalam koleksi. Secara default, metode ini menghitung kemunculan setiap elemen, memungkinkan Anda menghitung "tipe" elemen tertentu dalam koleksi

$collection = collect([1, 2, 3]);

_8

Anda melewati penutupan ke metode

use Illuminate\Support\Collection;

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 untuk menghitung semua item dengan nilai khusus

$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

Metode

use Illuminate\Support\Collection;

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 menggabungkan nilai koleksi di antara array atau koleksi yang diberikan, mengembalikan produk Cartesian dengan semua kemungkinan permutasi

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 membuang item koleksi dan mengakhiri eksekusi skrip

use Illuminate\Support\Collection;

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

Jika Anda tidak ingin menghentikan eksekusi skrip, gunakan metode ini

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 membandingkan koleksi dengan koleksi lain atau PHP biasa

use Illuminate\Support\Collection;

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 berdasarkan nilainya. Metode ini akan mengembalikan nilai dalam koleksi asli yang tidak ada dalam koleksi yang diberikan

use Illuminate\Support\Collection;

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

Catatan
Perilaku metode ini diubah saat menggunakan

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 membandingkan koleksi dengan koleksi lain atau PHP biasa

use Illuminate\Support\Collection;

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 berdasarkan kunci dan nilainya. Metode ini akan mengembalikan pasangan kunci/nilai di koleksi asli yang tidak ada di koleksi yang diberikan

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 membandingkan koleksi dengan koleksi lain atau PHP biasa

use Illuminate\Support\Collection;

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 berdasarkan kuncinya. Metode ini akan mengembalikan pasangan kunci/nilai di koleksi asli yang tidak ada di koleksi yang diberikan

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 menentukan apakah koleksi tidak berisi item tertentu. Anda dapat melewati penutupan metode

use Illuminate\Support\Collection;

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 untuk menentukan apakah suatu elemen tidak ada dalam koleksi yang cocok dengan uji kebenaran yang diberikan

use Illuminate\Support\Collection;

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

Alternatifnya, Anda dapat meneruskan string ke metode

use Illuminate\Support\Collection;

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 untuk menentukan apakah koleksi tidak berisi nilai item yang diberikan

use Illuminate\Support\Collection;

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

Anda juga dapat meneruskan pasangan kunci / nilai ke metode

use Illuminate\Support\Collection;

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, yang akan menentukan apakah pasangan yang diberikan tidak ada dalam koleksi

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 menggunakan perbandingan "longgar" saat memeriksa nilai item, artinya string dengan nilai bilangan bulat akan dianggap sama dengan bilangan bulat dengan nilai yang sama

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 membuang item koleksi

use Illuminate\Support\Collection;

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

Jika Anda ingin menghentikan eksekusi skrip setelah membuang koleksi, gunakan metode ini

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 mengambil dan mengembalikan nilai duplikat dari koleksi

use Illuminate\Support\Collection;

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

Jika koleksi berisi larik atau objek, Anda dapat meneruskan kunci atribut yang ingin Anda periksa nilai duplikatnya

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_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();

_88

Metode ini memiliki tanda tangan yang sama dengan metode;

use Illuminate\Support\Collection;

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

Metode

use Illuminate\Support\Collection;

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 mengulangi item dalam koleksi dan meneruskan setiap item ke penutupan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_1

Jika Anda ingin berhenti mengulangi item, Anda dapat mengembalikan

use Illuminate\Support\Collection;

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 dari penutupan Anda

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_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();

_93

Metode

use Illuminate\Support\Collection;

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 mengulangi item koleksi, meneruskan setiap nilai item bersarang ke callback yang diberikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_3

Anda dapat menghentikan iterasi melalui item dengan mengembalikan

use Illuminate\Support\Collection;

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

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_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();

_96

Metode

use Illuminate\Support\Collection;

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 dapat digunakan untuk memverifikasi bahwa semua elemen koleksi lulus uji kebenaran yang diberikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_5

Jika koleksi kosong, metode

use Illuminate\Support\Collection;

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 akan mengembalikan nilai true

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_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();

_99

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_00 mengembalikan semua item dalam koleksi kecuali item dengan kunci yang ditentukan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_7

Untuk kebalikan dari

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_00, lihat metodenya

Catatan
Perilaku metode ini diubah saat menggunakan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_02

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_03 memfilter koleksi menggunakan panggilan balik yang diberikan, hanya menyimpan item yang lulus uji kebenaran yang diberikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_8

Jika tidak ada panggilan balik yang diberikan, semua entri koleksi yang setara dengan

use Illuminate\Support\Collection;

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

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_9

Untuk kebalikan dari

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_03, lihat metodenya

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_06

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_07 mengembalikan elemen pertama dalam koleksi yang lulus uji kebenaran yang diberikan

$average = collect([1, 1, 2, 4])->avg();

_0

Anda juga dapat memanggil metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_07 tanpa argumen untuk mendapatkan elemen pertama dalam koleksi. Jika koleksi kosong,

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_09 dikembalikan

$average = collect([1, 1, 2, 4])->avg();

_1

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_10

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_11 identik dengan metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

07;

$average = collect([1, 1, 2, 4])->avg();

_2

Anda juga dapat memanggil metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_11 tanpa argumen untuk mendapatkan elemen pertama dalam koleksi. Jika koleksi kosong, pengecualian

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

13 akan dilemparkan

$average = collect([1, 1, 2, 4])->avg();

_3

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_16

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_17 mengembalikan elemen pertama dalam koleksi dengan pasangan kunci/nilai yang diberikan

$average = collect([1, 1, 2, 4])->avg();

_4

Anda juga dapat memanggil metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_17 dengan operator pembanding

$average = collect([1, 1, 2, 4])->avg();

_5

Seperti metodenya, Anda dapat meneruskan satu argumen ke metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

17. Dalam skenario ini, metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_17 akan mengembalikan item pertama di mana nilai kunci item yang diberikan adalah "kebenaran"

$average = collect([1, 1, 2, 4])->avg();

_6

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_21

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_22 mengulang melalui koleksi dan meneruskan setiap nilai ke penutupan yang diberikan. Penutupan bebas untuk memodifikasi item dan mengembalikannya, sehingga membentuk koleksi item baru yang dimodifikasi. Kemudian, array diratakan satu tingkat

$average = collect([1, 1, 2, 4])->avg();

_7

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_23

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_24 meratakan kumpulan multidimensi menjadi satu dimensi

$average = collect([1, 1, 2, 4])->avg();

_8

Jika perlu, Anda dapat memberikan metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_24 argumen "kedalaman".

$average = collect([1, 1, 2, 4])->avg();

_9

Dalam contoh ini, memanggil

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_24 tanpa memberikan kedalaman juga akan meratakan array bersarang, menghasilkan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

27. Memberikan kedalaman memungkinkan Anda menentukan jumlah level array bersarang yang akan diratakan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_28

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_29 menukar kunci koleksi dengan nilainya yang sesuai

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

0

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_30

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_31 menghapus item dari koleksi dengan kuncinya

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

1

Peringatan
Tidak seperti kebanyakan metode pengumpulan lainnya,

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_31 tidak mengembalikan koleksi baru yang dimodifikasi;

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_33

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_34 mengembalikan koleksi baru yang berisi item yang akan ada pada nomor halaman tertentu. Metode menerima nomor halaman sebagai argumen pertama dan jumlah item yang ditampilkan per halaman sebagai argumen kedua

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

2

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_35

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_36 mengembalikan item pada kunci yang diberikan. Jika kunci tidak ada,

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_09 dikembalikan

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

3

Anda dapat secara opsional memberikan nilai default sebagai argumen kedua

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

4

Anda bahkan dapat meneruskan callback sebagai nilai default metode. Hasil callback akan dikembalikan jika kunci yang ditentukan tidak ada

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

5

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_38

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_39 mengelompokkan item koleksi dengan kunci tertentu

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

6

Alih-alih meneruskan string

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

40, Anda dapat meneruskan panggilan balik. Panggilan balik harus mengembalikan nilai yang ingin Anda gunakan untuk memasukkan grup

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

7

Beberapa kriteria pengelompokan dapat diteruskan sebagai larik. Setiap elemen larik akan diterapkan ke tingkat yang sesuai dalam larik multidimensi

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

8

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_41

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_42 menentukan apakah kunci yang diberikan ada dalam koleksi

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_9

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_43

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_44 menentukan apakah ada kunci yang diberikan dalam koleksi

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

0

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_45

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_46 menggabungkan item dalam koleksi. Argumennya bergantung pada jenis item dalam koleksi. If the collection contains arrays or objects, you should pass the key of the attributes you wish to join, and the "glue" string you wish to place between the values

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

1

If the collection contains simple strings or numeric values, you should pass the "glue" as the only argument to the method

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

2

Anda dapat melewati penutupan metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_46 jika Anda ingin memformat nilai yang sedang diledakkan

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

3

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_48

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_49 menghapus nilai apa pun dari koleksi asli yang tidak ada dalam

use Illuminate\Support\Collection;

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 atau koleksi yang diberikan. Koleksi yang dihasilkan akan mempertahankan kunci koleksi asli

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

4

Catatan
Perilaku metode ini diubah saat menggunakan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_51

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_52 menghapus kunci apa pun dan nilainya yang sesuai dari koleksi asli yang tidak ada dalam

use Illuminate\Support\Collection;

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 atau koleksi yang diberikan

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

5

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_54

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

55 mengembalikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56 jika koleksi kosong;

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_58

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_59 mengembalikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56 jika koleksi tidak kosong;

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

6

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_62

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_63 menggabungkan nilai koleksi dengan sebuah string. Menggunakan argumen kedua metode ini, Anda juga dapat menentukan bagaimana elemen terakhir harus ditambahkan ke string

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

7

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_64

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_65 mengunci koleksi dengan kunci yang diberikan. Jika beberapa item memiliki kunci yang sama, hanya item terakhir yang akan muncul di koleksi baru

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

8

Anda juga dapat meneruskan panggilan balik ke metode. Callback harus mengembalikan nilai ke kunci koleksi

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

_9

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_66

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_67 mengembalikan semua kunci koleksi

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_0

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_68

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_69 mengembalikan elemen terakhir dalam koleksi yang lulus uji kebenaran yang diberikan

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_1

Anda juga dapat memanggil metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_69 tanpa argumen untuk mendapatkan elemen terakhir dalam koleksi. Jika koleksi kosong,

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_09 dikembalikan

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_2

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_72

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_73 mengembalikan instance baru dari array item yang mendasarinya

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_3

Ini sangat berguna ketika Anda perlu melakukan transformasi pada

use Illuminate\Support\Collection;

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 besar yang berisi banyak item

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_4

Dengan mengonversi koleksi menjadi

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_74, kami menghindari keharusan mengalokasikan satu ton memori tambahan. Meskipun koleksi asli masih menyimpan nilainya di memori, filter berikutnya tidak. Oleh karena itu, hampir tidak ada memori tambahan yang akan dialokasikan saat memfilter hasil koleksi

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_77

Metode

use Illuminate\Support\Collection;

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 statis memungkinkan Anda untuk menambahkan metode ke kelas

use Illuminate\Support\Collection;

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 saat dijalankan. Lihat dokumentasi di untuk informasi lebih lanjut

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_80

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_81 statis membuat instance koleksi baru. Lihat bagian

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_82

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_83 mengulang melalui koleksi dan meneruskan setiap nilai ke panggilan balik yang diberikan. Callback bebas untuk memodifikasi item dan mengembalikannya, sehingga membentuk kumpulan item baru yang dimodifikasi

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_5

Peringatan
Seperti kebanyakan metode pengumpulan lainnya,

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_83 mengembalikan contoh koleksi baru; . Jika Anda ingin mengubah koleksi aslinya, gunakan metode ini

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_86

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_86 mengulangi koleksi, membuat instance baru dari kelas yang diberikan dengan meneruskan nilai ke konstruktor

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_6

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_88

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_89 mengulangi item koleksi, meneruskan setiap nilai item bersarang ke dalam penutupan yang diberikan. Penutupan bebas untuk memodifikasi item dan mengembalikannya, sehingga membentuk koleksi item baru yang dimodifikasi

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_7

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_90

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_91 mengelompokkan item koleksi dengan penutupan yang diberikan. Penutupan harus mengembalikan larik asosiatif yang berisi pasangan kunci/nilai tunggal, sehingga membentuk kumpulan baru dari nilai yang dikelompokkan

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_8

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_92

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_93 mengulang melalui koleksi dan meneruskan setiap nilai ke panggilan balik yang diberikan. Callback harus mengembalikan larik asosiatif yang berisi pasangan kunci/nilai tunggal

$collection = collect(str_split('AABBCCCD'));

$chunks = $collection->chunkWhile(function ($value, $key, $chunk) {

return $value === $chunk->last();

// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]

_9

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_94

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_95 mengembalikan nilai maksimum dari kunci yang diberikan

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

0

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_96

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_97 mengembalikan nilai median dari kunci yang diberikan

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

1

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_98

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_99 menggabungkan array atau koleksi yang diberikan dengan koleksi asli. Jika kunci string dalam item yang diberikan cocok dengan kunci string dalam koleksi asli, nilai item yang diberikan akan menimpa nilai dalam koleksi asli

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

2

Jika kunci item yang diberikan adalah numerik, nilainya akan ditambahkan ke akhir koleksi

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

3

$average = collect([1, 1, 2, 4])->avg();

_00

Metode

$average = collect([1, 1, 2, 4])->avg();

_01 menggabungkan array atau koleksi yang diberikan secara rekursif dengan koleksi asli. Jika kunci string dalam item yang diberikan cocok dengan kunci string dalam koleksi asli, maka nilai untuk kunci ini digabungkan menjadi satu larik, dan ini dilakukan secara rekursif

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

4

$average = collect([1, 1, 2, 4])->avg();

_02

Metode

$average = collect([1, 1, 2, 4])->avg();

_03 mengembalikan nilai minimum dari kunci yang diberikan

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

5

$average = collect([1, 1, 2, 4])->avg();

_04

Metode

$average = collect([1, 1, 2, 4])->avg();

_05 mengembalikan nilai mode dari kunci yang diberikan

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

6

$average = collect([1, 1, 2, 4])->avg();

_06

Metode

$average = collect([1, 1, 2, 4])->avg();

_07 membuat koleksi baru yang terdiri dari setiap elemen ke-n

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

7

Anda dapat memberikan offset awal sebagai argumen kedua

$average = collect([1, 1, 2, 4])->avg();

_08

Metode

$average = collect([1, 1, 2, 4])->avg();

_09 mengembalikan item dalam koleksi dengan kunci yang ditentukan

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

8

Untuk kebalikan dari

$average = collect([1, 1, 2, 4])->avg();

_09, lihat metodenya

Catatan
Perilaku metode ini diubah saat menggunakan

$average = collect([1, 1, 2, 4])->avg();

_11

Metode

$average = collect([1, 1, 2, 4])->avg();

_12 akan mengisi array dengan nilai yang diberikan hingga array mencapai ukuran yang ditentukan. Metode ini berperilaku seperti fungsi PHP array_pad

Untuk bantalan ke kiri, Anda harus menentukan ukuran negatif. Padding tidak akan terjadi jika nilai absolut dari ukuran yang diberikan kurang dari atau sama dengan panjang array

$collapsed = $collection->collapse();

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

_9

$average = collect([1, 1, 2, 4])->avg();

_13

Metode

$average = collect([1, 1, 2, 4])->avg();

_14 dapat dikombinasikan dengan penghancuran array PHP untuk memisahkan elemen yang lulus uji kebenaran tertentu dari yang tidak

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

0

$average = collect([1, 1, 2, 4])->avg();

_15

Metode

$average = collect([1, 1, 2, 4])->avg();

_16 meneruskan koleksi ke penutupan yang diberikan dan mengembalikan hasil penutupan yang dieksekusi

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

1

$average = collect([1, 1, 2, 4])->avg();

_17

Metode

$average = collect([1, 1, 2, 4])->avg();

_18 membuat instance baru dari kelas yang diberikan dan meneruskan koleksi ke konstruktor

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

2

$average = collect([1, 1, 2, 4])->avg();

_19

Metode

$average = collect([1, 1, 2, 4])->avg();

_20 meneruskan koleksi ke larik penutupan yang diberikan dan mengembalikan hasil penutupan yang dieksekusi

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

3

$average = collect([1, 1, 2, 4])->avg();

_21

Metode

$average = collect([1, 1, 2, 4])->avg();

_22 mengambil semua nilai untuk kunci tertentu

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

4

Anda juga dapat menentukan bagaimana Anda ingin koleksi yang dihasilkan dikunci

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

5

Metode

$average = collect([1, 1, 2, 4])->avg();

_22 juga mendukung pengambilan nilai bersarang menggunakan notasi "titik"

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

6

Jika ada kunci duplikat, elemen pencocokan terakhir akan dimasukkan ke dalam koleksi yang dipetik

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

7

$average = collect([1, 1, 2, 4])->avg();

_24

Metode

$average = collect([1, 1, 2, 4])->avg();

_25 menghapus dan mengembalikan item terakhir dari koleksi

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

8

Anda dapat meneruskan bilangan bulat ke metode

$average = collect([1, 1, 2, 4])->avg();

25 untuk menghapus dan mengembalikan beberapa item dari akhir koleksi

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

8

$average = collect([1, 1, 2, 4])->avg();

_27

Metode

$average = collect([1, 1, 2, 4])->avg();

_28 menambahkan item ke awal koleksi

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

8

Anda juga dapat memberikan argumen kedua untuk menentukan kunci dari item yang diawali

$collection = collect([1, 2, 3]);

_01

$average = collect([1, 1, 2, 4])->avg();

_29

Metode

$average = collect([1, 1, 2, 4])->avg();

_30 menghapus dan mengembalikan item dari koleksi dengan kuncinya

$collection = collect([1, 2, 3]);

_02

$average = collect([1, 1, 2, 4])->avg();

_31

Metode

$average = collect([1, 1, 2, 4])->avg();

_32 menambahkan item ke akhir koleksi

$collection = collect([1, 2, 3]);

_7

$average = collect([1, 1, 2, 4])->avg();

_33

Metode

$average = collect([1, 1, 2, 4])->avg();

_34 menetapkan kunci dan nilai yang diberikan dalam koleksi

$collection = collect([1, 2, 3]);

_04

$average = collect([1, 1, 2, 4])->avg();

_35

Metode

$average = collect([1, 1, 2, 4])->avg();

_36 mengembalikan item acak dari koleksi

$collection = collect([1, 2, 3]);

_05

Anda dapat memberikan bilangan bulat ke

$average = collect([1, 1, 2, 4])->avg();

_36 untuk menentukan berapa banyak item yang ingin Anda ambil secara acak. Kumpulan item selalu dikembalikan saat secara eksplisit menyampaikan jumlah item yang ingin Anda terima

$collection = collect([1, 2, 3]);

_06

Jika instance koleksi memiliki item lebih sedikit dari yang diminta, metode

$average = collect([1, 1, 2, 4])->avg();

36 akan melempar

$average = collect([1, 1, 2, 4])->avg();

39

Metode

$average = collect([1, 1, 2, 4])->avg();

_36 juga menerima penutupan, yang akan menerima instance koleksi saat ini

$collection = collect([1, 2, 3]);

_07

$average = collect([1, 1, 2, 4])->avg();

_41

Metode

$average = collect([1, 1, 2, 4])->avg();

_42 mengembalikan koleksi yang berisi bilangan bulat antara rentang yang ditentukan

$collection = collect([1, 2, 3]);

_08

$average = collect([1, 1, 2, 4])->avg();

_43

Metode

$average = collect([1, 1, 2, 4])->avg();

_44 mengurangi koleksi menjadi satu nilai, meneruskan hasil dari setiap iterasi ke iterasi berikutnya

$collection = collect([1, 2, 3]);

_09

Nilai untuk

$average = collect([1, 1, 2, 4])->avg();

_45 pada iterasi pertama adalah

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

09;

$collection = collect([1, 2, 3]);

_10

Metode

$average = collect([1, 1, 2, 4])->avg();

_44 juga meneruskan kunci array dalam koleksi asosiatif ke panggilan balik yang diberikan

$collection = collect([1, 2, 3]);

_11

$average = collect([1, 1, 2, 4])->avg();

_49

Metode

$average = collect([1, 1, 2, 4])->avg();

_50 mengurangi koleksi menjadi array nilai, meneruskan hasil dari setiap iterasi ke iterasi berikutnya. Metode ini mirip dengan metode

$average = collect([1, 1, 2, 4])->avg();

_44;

$collection = collect([1, 2, 3]);

_12

$average = collect([1, 1, 2, 4])->avg();

_52

Metode

$average = collect([1, 1, 2, 4])->avg();

_53 memfilter koleksi menggunakan penutupan yang diberikan. Penutupan harus mengembalikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_56 jika item tersebut harus dihapus dari koleksi yang dihasilkan

$collection = collect([1, 2, 3]);

_13

Untuk kebalikan dari metode

$average = collect([1, 1, 2, 4])->avg();

_53, lihat metodenya

$average = collect([1, 1, 2, 4])->avg();

_57

Metode

$average = collect([1, 1, 2, 4])->avg();

_58 berperilaku serupa dengan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

99;

$collection = collect([1, 2, 3]);

_14

$average = collect([1, 1, 2, 4])->avg();

_61

Metode ini berfungsi seperti

$average = collect([1, 1, 2, 4])->avg();

_58, tetapi akan berulang menjadi array dan menerapkan proses penggantian yang sama ke nilai dalam

$collection = collect([1, 2, 3]);

_15

$average = collect([1, 1, 2, 4])->avg();

_63

Metode

$average = collect([1, 1, 2, 4])->avg();

_64 membalikkan urutan item koleksi, mempertahankan kunci asli

$collection = collect([1, 2, 3]);

_16

$average = collect([1, 1, 2, 4])->avg();

_65

Metode

$average = collect([1, 1, 2, 4])->avg();

_66 mencari koleksi untuk nilai yang diberikan dan mengembalikan kuncinya jika ditemukan. If the item is not found,

use Illuminate\Support\Collection;

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

$collection = collect([1, 2, 3]);

_17

The search is done using a "loose" comparison, meaning a string with an integer value will be considered equal to an integer of the same value. To use "strict" comparison, pass

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56 as the second argument to the method

$collection = collect([1, 2, 3]);

18

Alternatively, you may provide your own closure to search for the first item that passes a given truth test

$collection = collect([1, 2, 3]);

19

$average = collect([1, 1, 2, 4])->avg();

69

The

$average = collect([1, 1, 2, 4])->avg();

70 method removes and returns the first item from the collection

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

8

You may pass an integer to the

$average = collect([1, 1, 2, 4])->avg();

70 method to remove and return multiple items from the beginning of a collection

$collectionA = collect([1, 2, 3]);

$collectionB = $collectionA->collect();

8

$average = collect([1, 1, 2, 4])->avg();

72

The

$average = collect([1, 1, 2, 4])->avg();

73 method randomly shuffles the items in the collection

$collection = collect([1, 2, 3]);

22

$average = collect([1, 1, 2, 4])->avg();

74

The

$average = collect([1, 1, 2, 4])->avg();

75 method returns a new collection, with the given number of elements removed from the beginning of the collection

$collection = collect([1, 2, 3]);

23

$average = collect([1, 1, 2, 4])->avg();

76

The

$average = collect([1, 1, 2, 4])->avg();

77 method skips over items from the collection until the given callback returns

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56 and then returns the remaining items in the collection as a new collection instance

$collection = collect([1, 2, 3]);

24

You may also pass a simple value to the

$average = collect([1, 1, 2, 4])->avg();

77 method to skip all items until the given value is found

$collection = collect([1, 2, 3]);

25

Peringatan
If the given value is not found or the callback never returns

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56, the

$average = collect([1, 1, 2, 4])->avg();

77 method will return an empty collection

$average = collect([1, 1, 2, 4])->avg();

82

The

$average = collect([1, 1, 2, 4])->avg();

83 method skips over items from the collection while the given callback returns

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56 and then returns the remaining items in the collection as a new collection

$collection = collect([1, 2, 3]);

26

Peringatan
If the callback never returns

use Illuminate\Support\Collection;

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

$average = collect([1, 1, 2, 4])->avg();

83 method will return an empty collection

$average = collect([1, 1, 2, 4])->avg();

87

The

$average = collect([1, 1, 2, 4])->avg();

88 method returns a slice of the collection starting at the given index

$collection = collect([1, 2, 3]);

27

If you would like to limit the size of the returned slice, pass the desired size as the second argument to the method

$collection = collect([1, 2, 3]);

28

The returned slice will preserve keys by default. If you do not wish to preserve the original keys, you can use the method to reindex them

$average = collect([1, 1, 2, 4])->avg();

90

The

$average = collect([1, 1, 2, 4])->avg();

91 method returns a new collection of chunks representing a "sliding window" view of the items in the collection

$collection = collect([1, 2, 3]);

29

This is especially useful in conjunction with the method

$collection = collect([1, 2, 3]);

30

You may optionally pass a second "step" value, which determines the distance between the first item of every chunk

$collection = collect([1, 2, 3]);

31

$average = collect([1, 1, 2, 4])->avg();

93

The

$average = collect([1, 1, 2, 4])->avg();

94 method returns the first element in the collection that passes a given truth test, but only if the truth test matches exactly one element

$collection = collect([1, 2, 3]);

32

You may also pass a key / value pair to the

$average = collect([1, 1, 2, 4])->avg();

94 method, which will return the first element in the collection that matches the given pair, but only if it exactly one element matches

$collection = collect([1, 2, 3]);

33

Alternatively, you may also call the

$average = collect([1, 1, 2, 4])->avg();

94 method with no argument to get the first element in the collection if there is only one element

$collection = collect([1, 2, 3]);

34

If there are no elements in the collection that should be returned by the

$average = collect([1, 1, 2, 4])->avg();

94 method, an

$average = collect([1, 1, 2, 4])->avg();

98 exception will be thrown. If there is more than one element that should be returned, an

$average = collect([1, 1, 2, 4])->avg();

99 will be thrown

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

00

Alias ​​untuk metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

02

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_03 mengurutkan koleksi. Koleksi yang diurutkan menyimpan kunci larik asli, jadi dalam contoh berikut kita akan menggunakan metode untuk mengatur ulang kunci ke indeks bernomor berurutan

$collection = collect([1, 2, 3]);

_35

Jika kebutuhan penyortiran Anda lebih lanjut, Anda dapat meneruskan panggilan balik ke

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

03 dengan algoritme Anda sendiri. Lihat dokumentasi PHP di , yang digunakan oleh panggilan metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

03 koleksi secara internal

Catatan
Jika Anda perlu mengurutkan kumpulan array atau objek bersarang, lihat metode dan

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

10

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_08 mengurutkan koleksi dengan kunci yang diberikan. Koleksi yang diurutkan menyimpan kunci larik asli, jadi dalam contoh berikut kita akan menggunakan metode untuk mengatur ulang kunci ke indeks bernomor berurutan

$collection = collect([1, 2, 3]);

_36

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_08 menerima sort flag sebagai argumen kedua

$collection = collect([1, 2, 3]);

_37

Alternatifnya, Anda dapat melewati penutupan Anda sendiri untuk menentukan cara mengurutkan nilai koleksi

$collection = collect([1, 2, 3]);

_38

Jika Anda ingin mengurutkan koleksi Anda dengan beberapa atribut, Anda dapat meneruskan array operasi pengurutan ke metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

08. Setiap operasi pengurutan harus berupa larik yang terdiri dari atribut yang ingin Anda urutkan dan arah pengurutan yang diinginkan

$collection = collect([1, 2, 3]);

_39

Saat mengurutkan koleksi berdasarkan beberapa atribut, Anda juga dapat menyediakan penutupan yang menentukan setiap operasi pengurutan

$collection = collect([1, 2, 3]);

_40

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

15

Metode ini memiliki signature yang sama dengan metode, tetapi akan mengurutkan koleksi dalam urutan yang berlawanan

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_17

Metode ini akan mengurutkan koleksi dalam urutan yang berlawanan dengan metode

$collection = collect([1, 2, 3]);

_41

Tidak seperti

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_03, Anda tidak boleh melewati penutupan ke

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

20. Sebagai gantinya, Anda harus menggunakan metode dan membalikkan perbandingan Anda

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

22

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_23 mengurutkan koleksi dengan kunci dari array asosiatif yang mendasarinya

$collection = collect([1, 2, 3]);

_42

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_24

Metode ini memiliki signature yang sama dengan metode, tetapi akan mengurutkan koleksi dalam urutan yang berlawanan

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_26

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_27 mengurutkan koleksi dengan kunci array asosiatif yang mendasarinya menggunakan panggilan balik

$collection = collect([1, 2, 3]);

_43

Callback harus berupa fungsi perbandingan yang mengembalikan bilangan bulat kurang dari, sama dengan, atau lebih besar dari nol. Untuk informasi lebih lanjut, lihat dokumentasi PHP di , yang merupakan fungsi PHP yang digunakan metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

27 secara internal

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

30

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_31 menghapus dan mengembalikan sepotong item mulai dari indeks yang ditentukan

$collection = collect([1, 2, 3]);

_44

Anda dapat memberikan argumen kedua untuk membatasi ukuran koleksi yang dihasilkan

$collection = collect([1, 2, 3]);

_45

Selain itu, Anda dapat memberikan argumen ketiga yang berisi item baru untuk menggantikan item yang dihapus dari koleksi

$collection = collect([1, 2, 3]);

_46

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_32

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_33 memecah koleksi menjadi sejumlah grup yang diberikan

$collection = collect([1, 2, 3]);

_47

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_34

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_35 memecah koleksi menjadi sejumlah grup tertentu, mengisi grup non-terminal sepenuhnya sebelum mengalokasikan sisanya ke grup akhir

$collection = collect([1, 2, 3]);

_48

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_36

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_37 mengembalikan jumlah semua item dalam koleksi

$collection = collect([1, 2, 3]);

_49

Jika koleksi berisi array atau objek bersarang, Anda harus memberikan kunci yang akan digunakan untuk menentukan nilai mana yang akan dijumlahkan

$collection = collect([1, 2, 3]);

_50

Selain itu, Anda dapat melewati penutupan Anda sendiri untuk menentukan nilai koleksi mana yang akan dijumlahkan

$collection = collect([1, 2, 3]);

_51

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_38

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_39 mengembalikan koleksi baru dengan jumlah item yang ditentukan

$collection = collect([1, 2, 3]);

_52

Anda juga dapat memberikan bilangan bulat negatif untuk mengambil jumlah item yang ditentukan dari akhir koleksi

$collection = collect([1, 2, 3]);

_53

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_40

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_41 mengembalikan item dalam koleksi hingga panggilan balik yang diberikan mengembalikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56

$collection = collect([1, 2, 3]);

_54

Anda juga dapat memberikan nilai sederhana ke metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

41 untuk mendapatkan item hingga nilai yang diberikan ditemukan

$collection = collect([1, 2, 3]);

_55

Peringatan
Jika nilai yang diberikan tidak ditemukan atau panggilan balik tidak pernah mengembalikan

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56, metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

41 akan mengembalikan semua item dalam koleksi

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_46

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_47 mengembalikan item dalam koleksi hingga panggilan balik yang diberikan mengembalikan

use Illuminate\Support\Collection;

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

Peringatan
Jika panggilan balik tidak pernah mengembalikan

use Illuminate\Support\Collection;

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

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

47 akan mengembalikan semua item dalam koleksi

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

51

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_52 meneruskan koleksi ke panggilan balik yang diberikan, memungkinkan Anda untuk "mengetuk" koleksi pada titik tertentu dan melakukan sesuatu dengan item tanpa memengaruhi koleksi itu sendiri. Koleksi kemudian dikembalikan dengan metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

52

$collection = collect([1, 2, 3]);

_57

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

54

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_55 statis membuat koleksi baru dengan memanggil penutupan yang diberikan beberapa kali

$collection = collect([1, 2, 3]);

_58

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

56

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_57 mengubah koleksi menjadi PHP biasa

use Illuminate\Support\Collection;

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. Jika nilai koleksi adalah model Eloquent, model juga akan dikonversi menjadi array

$collection = collect([1, 2, 3]);

_59

Peringatan

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

57 juga mengonversi semua objek bersarang koleksi yang merupakan turunan dari

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

60 menjadi sebuah larik. Jika Anda ingin mendapatkan array mentah yang mendasari koleksi, gunakan metode ini

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_62

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_63 mengubah koleksi menjadi string serial JSON

$collection = collect([1, 2, 3]);

_60

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_64

Metode

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_85 mengulangi koleksi dan memanggil panggilan balik yang diberikan dengan setiap item dalam koleksi. Item dalam koleksi akan diganti dengan nilai yang dikembalikan oleh callback

$collection = collect([1, 2, 3]);

_61

Peringatan
Tidak seperti kebanyakan metode pengumpulan lainnya,

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

_85 memodifikasi koleksi itu sendiri. Jika Anda ingin membuat koleksi baru, gunakan metode ini

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_68

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_69 memperluas koleksi satu dimensi yang menggunakan notasi "titik" menjadi koleksi multidimensi

$collection = collect([1, 2, 3]);

_62

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

70

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_71 menambahkan array yang diberikan ke koleksi. Jika larik yang diberikan berisi kunci yang sudah ada di koleksi asli, nilai koleksi asli akan lebih disukai

$collection = collect([1, 2, 3]);

_63

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

72

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_73 mengembalikan semua item unik dalam koleksi. Koleksi yang dikembalikan menyimpan kunci larik asli, jadi dalam contoh berikut kita akan menggunakan metode untuk mengatur ulang kunci ke indeks bernomor berurutan

$collection = collect([1, 2, 3]);

_64

Saat berhadapan dengan array atau objek bersarang, Anda dapat menentukan kunci yang digunakan untuk menentukan keunikan

$collection = collect([1, 2, 3]);

_65

Terakhir, Anda juga dapat meneruskan penutupan Anda sendiri ke metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

73 untuk menentukan nilai mana yang harus menentukan keunikan item

$collection = collect([1, 2, 3]);

_66

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_73 menggunakan perbandingan "longgar" saat memeriksa nilai item, artinya string dengan nilai bilangan bulat akan dianggap sama dengan bilangan bulat dengan nilai yang sama. Gunakan metode untuk memfilter menggunakan perbandingan "ketat".

Catatan
Perilaku metode ini diubah saat menggunakan

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_78

Metode ini memiliki tanda tangan yang sama dengan metode;

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

80

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_81 akan mengeksekusi panggilan balik yang diberikan kecuali argumen pertama yang diberikan ke metode bernilai

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56

$collection = collect([1, 2, 3]);

_67

Callback kedua dapat diteruskan ke metode ________30______81. Callback kedua akan dieksekusi ketika argumen pertama yang diberikan ke metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

81 bernilai

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56

$collection = collect([1, 2, 3]);

_68

Untuk kebalikan dari

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_81, lihat metodenya

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_88

Alias ​​untuk metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_90

Alias ​​untuk metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_92

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_93 statis mengembalikan item yang mendasari koleksi dari nilai yang diberikan bila berlaku

$collection = collect([1, 2, 3]);

_69

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_94

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_95 mengambil nilai yang diberikan dari elemen pertama koleksi

$collection = collect([1, 2, 3]);

_70

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_96

Metode

$average = collect([1, 1, 2, 4])->avg();

_89 mengembalikan koleksi baru dengan kunci reset ke bilangan bulat berurutan

$collection = collect([1, 2, 3]);

_71

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_98

Metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_87 akan mengeksekusi panggilan balik yang diberikan saat argumen pertama yang diberikan ke metode bernilai

use Illuminate\Support\Collection;

use Illuminate\Support\Facades\Lang;

Collection::macro('toLocale', function ($locale) {

return $this->map(function ($value) use ($locale) {

return Lang::get($value, [], $locale);

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

$translated = $collection->toLocale('es');

56. Contoh koleksi dan argumen pertama yang diberikan ke metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

87 akan diberikan ke penutupan

$collection = collect([1, 2, 3]);

_72

Panggilan balik kedua dapat diteruskan ke metode ________30______87. Callback kedua akan dieksekusi ketika argumen pertama yang diberikan ke metode

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

87 bernilai

use Illuminate\Support\Collection;

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

Untuk kebalikan dari

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

_87, lihat metodenya

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

07

The

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

91 method will execute the given callback when the collection is empty

$collection = collect([1, 2, 3]);

74

A second closure may be passed to the

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

91 method that will be executed when the collection is not empty

$collection = collect([1, 2, 3]);

75

For the inverse of

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

91, see the method

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

12

The

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

89 method will execute the given callback when the collection is not empty

$collection = collect([1, 2, 3]);

76

A second closure may be passed to the

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

89 method that will be executed when the collection is empty

$collection = collect([1, 2, 3]);

77

For the inverse of

$collection = collect([1, 2, 3, 4, 5, 6, 7]);

$chunks = $collection->chunk(4);

// [[1, 2, 3, 4], [5, 6, 7]]

89, see the method

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

17

The

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

18 method filters the collection by a given key / value pair

$collection = collect([1, 2, 3]);

78

The

@foreach ($products->chunk(3) as $chunk)

@foreach ($chunk as $product)

{{ $product->name }}

18 method uses "loose" comparisons when checking item values, meaning a string with an integer value will be considered equal to an integer of the same value. Use the method to filter using "strict" comparisons

Optionally, you may pass a comparison operator as the second parameter. Supported operators are: '===', '!==', '!=', '==', '=', '', '>', '=', and '

Postingan terbaru

LIHAT SEMUA