Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel collection get price sum

$collection = collect([
    ['name' => 'Chair', 'colors' => ['Black']],
    ['name' => 'Desk', 'colors' => ['Black', 'Mahogany']],
    ['name' => 'Bookcase', 'colors' => ['Red', 'Beige', 'Brown']],
]);
 
$collection->sum(function ($product) {
    return count($product['colors']);
});
 
 
PREVIOUS NEXT
Tagged: #laravel #collection #price #sum
ADD COMMENT
Topic
Name
2+1 =