3v4l.org

run code in 300+ PHP versions simultaneously
<?php $flat = [ ['id' => 100, 'parent_id' => 0, 'name' => 'root'], ['id' => 101, 'parent_id' => 100, 'name' => 'ch-1'], ['id' => 102, 'parent_id' => 101, 'name' => 'ch-1-1'], ['id' => 103, 'parent_id' => 101, 'name' => 'ch-1-2'], ['id' => 104, 'parent_id' => 101, 'name' => 'ch-1-2'], ['id' => 105, 'parent_id' => 104, 'name' => 'ch-1-2'], ['id' => 106, 'parent_id' => 101, 'name' => 'ch-1-2'], ['id' => 107, 'parent_id' => 101, 'name' => 'ch-1-2'], ]; $new = array(); foreach ($flat as $a){ $new[$a['parent_id']][] = $a; } $tree = createTree($new, array($flat[0])); print_r($tree); function createTree(&$list, $parent){ $tree = array(); foreach ($parent as $k=>$l){ if(isset($list[$l['id']])){ $l['children'] = createTree($list, $list[$l['id']]); } $tree[] = $l; } return $tree; }
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [id] => 100 [parent_id] => 0 [name] => root [children] => Array ( [0] => Array ( [id] => 101 [parent_id] => 100 [name] => ch-1 [children] => Array ( [0] => Array ( [id] => 102 [parent_id] => 101 [name] => ch-1-1 ) [1] => Array ( [id] => 103 [parent_id] => 101 [name] => ch-1-2 ) [2] => Array ( [id] => 104 [parent_id] => 101 [name] => ch-1-2 [children] => Array ( [0] => Array ( [id] => 105 [parent_id] => 104 [name] => ch-1-2 ) ) ) [3] => Array ( [id] => 106 [parent_id] => 101 [name] => ch-1-2 ) [4] => Array ( [id] => 107 [parent_id] => 101 [name] => ch-1-2 ) ) ) ) ) )

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:
39.9 ms | 416 KiB | 5 Q