<?php $array = [ ['id' => 'abc-abc-12', 'qty' => 0, 'locationID' => 276, 'CC_qty' => 250, 'Location' => 'NOP11'], ['id' => 'abc-abc-12', 'qty' => 0, 'locationID' => 310, 'CC_qty' => 1385, 'Location' => 'NOP01'], ['id' => 'abc-abc-23', 'qty' => 0, 'locationID' => 84, 'CC_qty' => 116, 'Location' => 'NOP06'], ['id' => 'abc-abc-23', 'qty' => 0, 'locationID' => 254, 'CC_qty' => 432, 'Location' => 'NOP08'], ['id' => 'abc-abc-23', 'qty' => 0, 'locationID' => 228, 'CC_qty' => 101, 'Location' => 'NOP04'], ['id' => 'abc-abc-34', 'qty' => 0, 'locationID' => 254, 'CC_qty' => 436, 'Location' => 'NOP08'], ['id' => 'abc-abc-34', 'qty' => 0, 'locationID' => 254, 'CC_qty' => 62, 'Location' => 'NOP08'], ['id' => 'abc-abc-45', 'qty' => 0, 'locationID' => 75, 'CC_qty' => 89, 'Location' => 'NOP05'], ['id' => 'abc-abc-45', 'qty' => 0, 'locationID' => 202, 'CC_qty' => 372, 'Location' => 'NOP07'], ]; $result = []; foreach ($array as $row) { if (!isset($result[$row['id']])) { $result[$row['id']] = $row; } else { $result[$row['id']]['qty'] += $row['qty']; // SUM $result[$row['id']]['locationID'] .= ", " . $row['locationID']; // CONCAT $result[$row['id']]['CC_qty'] += $row['CC_qty']; // SUM $result[$row['id']]['Location'] .= ", " . $row['Location']; // CONCAT } } var_export(array_values($result));
You have javascript disabled. You will not be able to edit any code.