3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['name' => 'blah', 'path' => 'A'], ['name' => 'blah', 'path' => 'AA'], ['name' => 'blah', 'path' => 'AB'], ['name' => 'blah', 'path' => 'C'], ['name' => 'blah', 'path' => 'D'], ['name' => 'blah', 'path' => 'B'], ['name' => 'blah', 'path' => 'BA'], ['name' => 'blah', 'path' => 'BAA'], ['name' => 'blah', 'path' => 'CA'], ]; function rowsToTree(&$array, $parent = '') { $children = []; foreach ($array as $i => &$row) { if ($parent === substr($row['path'], 0, -1)) { $found = rowsToTree($array, $row['path']); if ($found) { $row['children'] = $found; if ($parent) { unset($array[$i]); } } if ($parent) { $children[] = $row; unset($array[$i]); } } } return $children; } rowsToTree($rows); var_export($rows);
Output for git.master_jit, git.master, rfc.property-hooks
array ( 0 => array ( 'name' => 'blah', 'path' => 'A', 'children' => array ( 0 => array ( 'name' => 'blah', 'path' => 'AA', ), 1 => array ( 'name' => 'blah', 'path' => 'AB', ), ), ), 3 => array ( 'name' => 'blah', 'path' => 'C', 'children' => array ( 0 => array ( 'name' => 'blah', 'path' => 'CA', ), ), ), 4 => array ( 'name' => 'blah', 'path' => 'D', ), 5 => array ( 'name' => 'blah', 'path' => 'B', 'children' => array ( 0 => array ( 'name' => 'blah', 'path' => 'BA', 'children' => array ( 0 => array ( 'name' => 'blah', 'path' => 'BAA', ), ), ), ), ), )

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:
135.21 ms | 408 KiB | 5 Q