3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [ [ 'id' => 1, 'user_id' => 9788, 'contact_id' => 10083, 'product_id' => 1, 'category_id' => 23, 'grade' => 'A', 'point' => 89, ], [ 'id' => 1, 'user_id' => 9788, 'contact_id' => 10083, 'product_id' => 2, 'category_id' => 27, 'grade' => 'A', 'point' => 89, ] ]; $groupedArr = array_reduce($arr, function ($a, $c) { $a[$c['user_id']] = [ 'user_id' => $c['user_id'], 'contact_id' => $c['contact_id'], 'attributes' => array_merge([[ 'product_id' => $c['product_id'], 'category_id' => $c['category_id'] ]], $a[$c['user_id']]['attributes'] ?? []), 'grade' => $c['grade'], 'point' => $c['point'] ]; return $a; }, []); echo json_encode(array_values($groupedArr), JSON_PRETTY_PRINT);
Output for git.master, git.master_jit, rfc.property-hooks
[ { "user_id": 9788, "contact_id": 10083, "attributes": [ { "product_id": 2, "category_id": 27 }, { "product_id": 1, "category_id": 23 } ], "grade": "A", "point": 89 } ]

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:
47.7 ms | 894 KiB | 4 Q