3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = [ ['part' => '1', 'address' => 'aaa', 'type' => '1', 'count' => 5], ['part' => '1', 'address' => 'bbb', 'type' => '1', 'count' => 5], ['part' => '1', 'address' => 'ccc', 'type' => '1', 'count' => 5], ['part' => '2', 'address' => 'aaa', 'type' => '1', 'count' => 5], ['part' => '2', 'address' => 'bbb', 'type' => '1', 'count' => 5], ['part' => '2', 'address' => 'ccc', 'type' => '2', 'count' => 5] ]; $result = []; foreach ($arr1 as $row) { $compositeKey = $row['part'] . '-' . $row['type']; $result[$compositeKey] = [ 'part' => $row['part'], 'type' => $row['type'], 'count' => ($result[$compositeKey]['count'] ?? 0) + $row['count'] ]; } var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'part' => '1', 'type' => '1', 'count' => 15, ), 1 => array ( 'part' => '2', 'type' => '1', 'count' => 10, ), 2 => array ( 'part' => '2', 'type' => '2', 'count' => 5, ), )

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:
27.56 ms | 406 KiB | 5 Q