3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ "menu_id" => 7, "menu_name" => "Kasagbutan Meals", "menu_price" => "100.00", "qty" => "1", "special_instructions" => "" ], [ "menu_id" => 7, "special_instructions" => "", "menu_name" => "Kasagbutan Meals", "menu_price" => "100.00", "qty" => "1", ], [ "menu_id" => 6, "menu_name" => "Coke", "menu_price" => "50.00", "qty" => "1", "special_instructions" => "" ] ]; $exclude = array_flip(['qty']); $totals = array_reduce($arr, function($totals, $item) use ($exclude) { $id = array_diff_key($item, $exclude); ksort($id); $hash = crc32(json_encode($id)); if (array_key_exists($hash, $totals)) { $totals[$hash]['qty'] += $item['qty']; } else { $totals[$hash] = $item; } return $totals; }, []); print_r($totals);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [2369868709] => Array ( [menu_id] => 7 [menu_name] => Kasagbutan Meals [menu_price] => 100.00 [qty] => 2 [special_instructions] => ) [1141584172] => Array ( [menu_id] => 6 [menu_name] => Coke [menu_price] => 50.00 [qty] => 1 [special_instructions] => ) )

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