Answers for "laravel collection->push with key"

PHP
4

collection laravel filter

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

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

$filtered->all();

// [3, 4]
Posted by: Guest on November-17-2020
0

laravel reduce

$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
Posted by: Guest on December-14-2020
0

laravel collection push

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

$collection->push(5);

$collection->all();

// [1, 2, 3, 4, 5]
Posted by: Guest on May-27-2020

Code answers related to "laravel collection->push with key"

Browse Popular Code Answers by Language