3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = [ (object) ['group_id' => 'a', 'price' => 10, 'options_count' => 3], (object) ['group_id' => 'a', 'price' => 15, 'options_count' => 2], (object) ['group_id' => 'b', 'price' => 55, 'options_count' => 4], (object) ['group_id' => 'c', 'price' => 75, 'options_count' => 5], ]; $totals = []; foreach($items as $item) { $group_identifier = $item->group_id; @$totals[ $group_identifier ]['turnover'] += $item->price; @$totals[ $group_identifier ]['products']++; @$totals[ $group_identifier ]['options'] += $item->options_count; } var_dump($totals);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { ["a"]=> array(3) { ["turnover"]=> int(25) ["products"]=> int(2) ["options"]=> int(5) } ["b"]=> array(3) { ["turnover"]=> int(55) ["products"]=> int(1) ["options"]=> int(4) } ["c"]=> array(3) { ["turnover"]=> int(75) ["products"]=> int(1) ["options"]=> int(5) } }

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