3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'parent' => 'Basic', 'parentId' => 1, 'child' => 'Birthday', 'childId' => 2, ], [ 'parent' => 'Basic', 'parentId' => 1, 'child' => 'Gender', 'childId' => 3, ], [ 'parent' => 'Geo', 'parentId' => 10, 'child' => 'Current City', 'childId' => 11, ], [ 'parent' => 'Known me', 'parentId' => 5, 'child' => 'My personality', 'childId' => 7, ], [ 'parent' => 'Known me', 'parentId' => 5, 'child' => 'Best life moment', 'childId' => 8, ], ]; $result = []; foreach ($array as $row) { if (!isset($result[$row['parentId']])) { $result[$row['parentId']] = [ 'parent' => $row['parent'], 'parentId' => $row['parentId'], 'child' => [$row['child']] ]; } else { $result[$row['parentId']]['child'][] = $row['child']; } } var_export(array_values($result));
Output for git.master_jit, git.master, rfc.property-hooks
array ( 0 => array ( 'parent' => 'Basic', 'parentId' => 1, 'child' => array ( 0 => 'Birthday', 1 => 'Gender', ), ), 1 => array ( 'parent' => 'Geo', 'parentId' => 10, 'child' => array ( 0 => 'Current City', ), ), 2 => array ( 'parent' => 'Known me', 'parentId' => 5, 'child' => array ( 0 => 'My personality', 1 => 'Best life moment', ), ), )

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.66 ms | 406 KiB | 5 Q