3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<EOL [ { "tax": "10", "concept": "TUC", "val": "10" }, { "tax": "10", "concept": "TUC", "val": "86" }, { "tax": "15", "concept": "TUC", "val": "8" }, { "tax": "11", "concept": "IPS", "val": "6" }, { "tax": "11", "concept": "IPS", "val": "45" } ] EOL; $array = json_decode($str); $result = array_reduce($array, function($carry, $item) { if(!isset($carry[$item->tax])) { $carry[$item->tax] = $item; } else { $carry[$item->tax]->val += $item->val; } return $carry; }); $result = array_values($result); print_r(json_encode($result));
Output for git.master, git.master_jit, rfc.property-hooks
[{"tax":"10","concept":"TUC","val":96},{"tax":"15","concept":"TUC","val":"8"},{"tax":"11","concept":"IPS","val":51}]

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.06 ms | 405 KiB | 5 Q