“Filter koleksi Laravel” Kode Jawaban

Filter koleksi Laravel

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

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

$filtered->all();

// [3, 4]
Relieved Raccoon

Laravel berkurang

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

$total = $collection->reduce(function ($carry, $item) {
    return $carry + $item;
});

// 6

$total = $collection->reduce(function ($carry, $item) {
    return $carry + $item;
}, 4);

// 10   | where 4 is a initial value
Lokesh003

koleksi filter (Laravel)

$itemCollection = collect($contacts);
$filtered = $itemCollection->filter(function($item) use ($search) {
    return stripos($item['username'],$search) !== false;
});

Metode pengumpulan Laravel

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

$collection->each(function($item){
    return $item*$item;
});

// [1,4,9,16]
Weary Weasel

Jawaban yang mirip dengan “Filter koleksi Laravel”

Pertanyaan yang mirip dengan “Filter koleksi Laravel”

Lebih banyak jawaban terkait untuk “Filter koleksi Laravel” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya