“Koleksi Gabungan Laravel” Kode Jawaban

koleksi filter laravel

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

$filtered = $collection->filter(function ($value, $key) {
    return $value > 2;
});

$filtered->all();

// [3, 4]
Relieved Raccoon

Koleksi Gabungan Laravel

/* 
 * The merge method merges the given array or collection with the original collection.
 * If a string key in the given items matches a string key in the original collection,
 * the given items's value will overwrite the value in the original collection:
 */
$collection = collect(['product_id' => 1, 'price' => 100]);
$merged = $collection->merge(['price' => 200, 'discount' => false]);
$merged->all(); // ['product_id' => 1, 'price' => 200, 'discount' => false]

// If the given items's keys are numeric, the values will be appended to the end of the collection:
$collection = collect(['Desk', 'Chair']);
$merged = $collection->merge(['Bookcase', 'Door']);
$merged->all(); // ['Desk', 'Chair', 'Bookcase', 'Door']
Yingfufu

Gabungkan Koleksi Laravel

$collection = collect(['product_id' => 1, 'price' => 100]);

$merged = $collection->merge(['price' => 200, 'discount' => false]);

$merged->all();

// ['product_id' => 1, 'price' => 200, 'discount' => false]
Tough Tarsier

memetik laravel

$name = DB::table('users')->where('name', 'John')->pluck('name');
Lokesh003

Gabungkan dua koleksi (Laravel)

$foo = collect(Foo::all());
$bar = collect(Bar::all());
$merged = $foo->merge($bar);

Irfan

Jawaban yang mirip dengan “Koleksi Gabungan Laravel”

Pertanyaan yang mirip dengan “Koleksi Gabungan Laravel”

Lebih banyak jawaban terkait untuk “Koleksi Gabungan Laravel” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya