3v4l.org

run code in 300+ PHP versions simultaneously
<?php $the_array = [ ['id' => 1, 'value' => 10, 'name' => 'apple'], ['id' => 1, 'value' => 20, 'name' => 'orange'], ['id' => 1, 'value' => 30, 'name' => 'banana'], ['id' => 2, 'value' => 100, 'name' => 'car'], ['id' => 2, 'value' => 200, 'name' => 'bicycle'], ]; var_export( array_values( array_reduce( $the_array, function ($carry, $row) { if (!isset($carry[$row['id']])) { $carry[$row['id']] = $row; } else { $carry[$row['id']]['value'] += $row['value']; $carry[$row['id']]['name'] .= ",{$row['name']}"; } return $carry; } ) ) );
Output for git.master_jit, git.master, rfc.property-hooks
array ( 0 => array ( 'id' => 1, 'value' => 60, 'name' => 'apple,orange,banana', ), 1 => array ( 'id' => 2, 'value' => 300, 'name' => 'car,bicycle', ), )

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