3v4l.org

run code in 300+ PHP versions simultaneously
<?php $basket = [ [ 'name' => 'apple', 'qty' => 5, ], [ 'name' => 'apple', 'qty' => 4, ], [ 'name' => 'pear', 'qty' => 4, ] ]; // need a function that would convert this to $output = []; foreach ($basket as $item) { $key = $item['name']; if (!isset($output[$key])) $output[$key] = 0; $output[$key] += $item['qty']; } var_dump($output); //$output = [['name' => 'apple', 'qty' => 9], ['name' => 'pear', 'qty' => 4]];
Output for git.master_jit, git.master, rfc.property-hooks
array(2) { ["apple"]=> int(9) ["pear"]=> int(4) }

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