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] ]; $productCounts = []; foreach ($array as $item) { $productId = $item['product']['_id']; $productCounts[$productId] = ($productCounts[$productId] ?? 0) + $item['count']; } var_export($productCounts);
Output for git.master, git.master_jit, rfc.property-hooks
array ( '5d0391a4a72ffe76b8fcc610' => 1, '5d0391b6a72ffe76b8fcc611' => 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:
48.65 ms | 401 KiB | 8 Q