3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['currency' => 'SGD', 'duration' => 8.00, 'cost' => 228.57], ['currency' => null, 'duration' => 8.00, 'cost' => null], ['currency' => 'MYR', 'duration' => 12.00, 'cost' => 342.86], ['currency' => 'SGD', 'duration' => 8.00, 'cost' => 228.57], ['currency' => 'MYR', 'duration' => 12.00, 'cost' => 342.86], ]; $result = []; foreach ($array as $row) { if (!isset($result[$row['currency']])) { $result[$row['currency']] = $row; } else { $result[$row['currency']]['duration'] += $row['duration']; $result[$row['currency']]['cost'] += $row['cost']; } } var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'currency' => 'SGD', 'duration' => 16.0, 'cost' => 457.14, ), 1 => array ( 'currency' => NULL, 'duration' => 8.0, 'cost' => NULL, ), 2 => array ( 'currency' => 'MYR', 'duration' => 24.0, 'cost' => 685.72, ), )

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