3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input_array = [ ['id' => 2, 'name' => 'ProductName', 'comment' => 'best product comment 1'], ['id' => 2, 'name' => 'ProductName', 'comment' => 'best product comment 2'], ['id' => 2, 'name' => 'ProductName', 'comment' => 'best product comment 3'], ['id' => 3, 'name' => 'ProductName2', 'comment' => 'best product comment 4'], ['id' => 3, 'name' => 'ProductName2', 'comment' => 'best product comment 5'] ]; $output_array = array_values(array_reduce($input_array, function($output_array, $item) { if (array_key_exists($item['id'], $output_array)) $output_array[$item['id']]['comment'][] = $item['comment']; else { $item['comment'] = (array)$item['comment']; $output_array[$item['id']] = $item; } return $output_array; }, [])); var_dump($output_array);
Output for git.master_jit, git.master, rfc.property-hooks
array(2) { [0]=> array(3) { ["id"]=> int(2) ["name"]=> string(11) "ProductName" ["comment"]=> array(3) { [0]=> string(22) "best product comment 1" [1]=> string(22) "best product comment 2" [2]=> string(22) "best product comment 3" } } [1]=> array(3) { ["id"]=> int(3) ["name"]=> string(12) "ProductName2" ["comment"]=> array(2) { [0]=> string(22) "best product comment 4" [1]=> string(22) "best product comment 5" } } }

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:
119.72 ms | 407 KiB | 5 Q