3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = array( [ 'menu_id' => 10, 'current_price' => 150, 'num' => 10 ], [ 'menu_id' => 12, 'current_price' => 200, 'num' => 20 ], [ 'menu_id' => 10, 'current_price' => 150, 'num' => 30 ], ['menu_id' => 11, 'current_price' => 100, 'num' => 40 ], [ 'menu_id' => 11, 'current_price' => 100, 'num' => 50 ], ['menu_id' => 11, 'current_price' => 200, 'num' => 60 ], ['menu_id' => 13, 'current_price' => 300, 'num' => 70 ] ) ; $grouped = []; foreach($items as $v){ $index = $v['menu_id'].'-'.$v['current_price']; isset($grouped[$index]) ? ($grouped[$index]['num'] += $v['num']) : ($grouped[$index] = $v); } print_r($grouped);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [10-150] => Array ( [menu_id] => 10 [current_price] => 150 [num] => 40 ) [12-200] => Array ( [menu_id] => 12 [current_price] => 200 [num] => 20 ) [11-100] => Array ( [menu_id] => 11 [current_price] => 100 [num] => 90 ) [11-200] => Array ( [menu_id] => 11 [current_price] => 200 [num] => 60 ) [13-300] => Array ( [menu_id] => 13 [current_price] => 300 [num] => 70 ) )

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