Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel collection sum array column

$collection = collect([
    ['name' => 'JavaScript: The Good Parts', 'pages' => 176, 'price' => 100.00],
    ['name' => 'JavaScript: The Definitive Guide', 'pages' => 314, 'price' => 150.00]
]);

$result = $collection->pipe(function ($collection) {
  return collect([
    'total_pages' => $collection->sum('pages'),
    'total_price' => $collection->sum('price'),
  ]);
});
 
PREVIOUS NEXT
Tagged: #laravel #collection #sum #array #column
ADD COMMENT
Topic
Name
6+3 =