3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 'Orders' => [ [ 'transaction_id' => '78078', 'date' => 1616277653, 'currency' => 'EUR', 'items' => [ ['title' => 'Title 1', 'quantity' => 200, 'price' => 2.1, 'sku' => '1T.810BK'], ['title' => 'Title 2', 'quantity' => 250, 'price' => 1.78, 'sku' => '1090.005BK'], ], ], [ 'transaction_id' => 78079, 'date' => 1616597838, 'currency' => 'EUR', 'items' => [ ['title' => 'title 3', 'quantity' => 3, 'price' => 118.3, 'sku' => '1.DIYBOX.ULT.638RE'], ], ], [ 'transaction_id' => 78080, 'date' => 1616598322, 'currency' => 'EUR', 'items' => [ ['title' => 'title 2', 'quantity' => 300, 'price' => 1.78, 'sku' => '1090.005BK'], ], ] ] ]; var_export( array_reduce( array_merge( ...array_column($data['Orders'], 'items') ), function($carry, $item) { $carry[$item['sku']] = ($carry[$item['sku']] ?? 0) + $item['quantity']; return $carry; } ) );
Output for git.master, git.master_jit, rfc.property-hooks
array ( '1T.810BK' => 200, '1090.005BK' => 550, '1.DIYBOX.ULT.638RE' => 3, )

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:
125.05 ms | 405 KiB | 5 Q