3v4l.org

run code in 300+ PHP versions simultaneously
<?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));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'id' => 'abc-abc-12', 'qty' => 0, 'locationID' => '276, 310', 'CC_qty' => 1635, 'Location' => 'NOP11, NOP01', ), 1 => array ( 'id' => 'abc-abc-23', 'qty' => 0, 'locationID' => '84, 254, 228', 'CC_qty' => 649, 'Location' => 'NOP06, NOP08, NOP04', ), 2 => array ( 'id' => 'abc-abc-34', 'qty' => 0, 'locationID' => '254, 254', 'CC_qty' => 498, 'Location' => 'NOP08, NOP08', ), 3 => array ( 'id' => 'abc-abc-45', 'qty' => 0, 'locationID' => '75, 202', 'CC_qty' => 461, 'Location' => 'NOP05, NOP07', ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
140.02 ms | 407 KiB | 5 Q