3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = json_decode('[{"name":"BBQ - Small (26cm)","params":"","price":"12.99"}, {"name":"Coca-cola 0.5","params":"","price":"1"}, {"name":"BBQ - Small (26cm)","params":"","price":"12.99"}, {"name":"BBQ - Mid (31cm)","params":"","price":"14.99"}, {"name":"BBQ - Small (26cm)","params":"","price":"12.99"}, {"name":"Bolognese - Small (26cm)","params":"","price":"12"}, {"name":"Coca-cola 0.5","params":"","price":"1"}, {"name":"BBQ - Small (26cm)","params":"","price":"12.99"}]', true); $new['total'] =0; foreach($arr as $sub){ if(!isset($new[$sub['name']]['count'])){ $new[$sub['name']]['count'] = 0; $new[$sub['name']]['total'] = 0; } $new[$sub['name']]['count']++; $new[$sub['name']]['total'] += $sub['price']; $new['total'] += $sub['price']; } var_export($new);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'total' => 80.95, 'BBQ - Small (26cm)' => array ( 'count' => 4, 'total' => 51.96, ), 'Coca-cola 0.5' => array ( 'count' => 2, 'total' => 2, ), 'BBQ - Mid (31cm)' => array ( 'count' => 1, 'total' => 14.99, ), 'Bolognese - Small (26cm)' => array ( 'count' => 1, 'total' => 12, ), )

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