3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['_id' => '5f76b1788ee23077dccd1a2c', 'product' => ['_id'=>'5d0391a4a72ffe76b8fcc610'], 'count'=> 1], ['_id' => '5f76b6288ee2300700cd1a3a', 'product' => ['_id'=>'5d0391b6a72ffe76b8fcc611'], 'count'=> 1], ['_id' => '5f76d2488ee23083d3cd1a4a', 'product' => ['_id'=>'5d0391b6a72ffe76b8fcc611'], 'count'=> 1] ]; $result = []; foreach ($array as $item) { $productId = $item['product']['_id']; if (!isset($result[$productId])) { $result[$productId] = $item; } else { $result[$productId]['count'] += $item['count']; } } var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( '_id' => '5f76b1788ee23077dccd1a2c', 'product' => array ( '_id' => '5d0391a4a72ffe76b8fcc610', ), 'count' => 1, ), 1 => array ( '_id' => '5f76b6288ee2300700cd1a3a', 'product' => array ( '_id' => '5d0391b6a72ffe76b8fcc611', ), 'count' => 2, ), )

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:
31.93 ms | 402 KiB | 8 Q