'amount' => 1 ], [ 'category' => 'Food', 'type' => 'pasta', 'amount' => 1 ], [ 'category' => 'Food', 'type' => 'juice', 'amount' => 1 ], [ 'category' => 'Food', 'type' => 'juice', 'amount' => 1 ], [ 'category' => 'Book', 'type' => 'programming', 'amount' => 5 ], [ 'category' => 'Book', 'type' => 'programming', 'amount' => 2 ], [ 'category' => 'Book', 'type' => 'cooking', 'amount' => 6 ], [ 'category' => 'Book', 'type' => 'cooking', 'amount' => 2 ], ]; $result = group_by($rows, ['category','type'], [ 'total_amount' => [ 'selector' => 'amount', 'aggregator' => REDUCER_AGGR_SUM, ], 'cnt' => REDUCER_AGGR_COUNT, ]); print_r($result);