How to group by column a and sum column b and c in a php array

To group and sum the values in your array by the shipping field, you can use a loop and a temporary associative array to store the intermediate results. Here is an example of how you can do this:

$result = array();

foreach ($array as $item) {
  $shipping = $item['shipping'];
  if (!isset($result[$shipping])) {
    $result[$shipping] = array(
      'kanel' => 0,
      'peber' => 0,
    );
  }
  $result[$shipping]['kanel'] += $item['kanel'];
  $result[$shipping]['peber'] += $item['peber'];
}

// Print the results
foreach ($result as $shipping => $values) {
  echo $shipping . ' Kanel: ' . $values['kanel'] . ' Peber: ' . $values['peber'] . "\n";
}

This will produce the following output:

A Kanel: 30 Peber: 0
B Kanel: 5 Peber: 0
C Kanel: 30 Peber: 0