3v4l.org

run code in 300+ PHP versions simultaneously
<?php $payments = [ ['bookingId' => 1, 'vendorId' => 3, 'amount' => 50], ['bookingId' => 1, 'vendorId' => 3, 'amount' => 85], ['bookingId' => 1, 'vendorId' => 4, 'amount' => 14], ]; $result = array_reduce( $payments, function(array $carry, array $payment): array { $carry[$payment['vendorId']] = $payment; $carry[$payment['vendorId']]['amount'] = ($carry[$payment['vendorId']]['amount'] ?? 0) + $payment['amount']; return $carry; }, [] ); var_dump(array_values($result));
Output for git.master_jit, git.master
array(2) { [0]=> array(3) { ["bookingId"]=> int(1) ["vendorId"]=> int(3) ["amount"]=> int(170) } [1]=> array(3) { ["bookingId"]=> int(1) ["vendorId"]=> int(4) ["amount"]=> int(28) } }

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