3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category = array( array('left' => 1, 'right' => 11, 'x' => 'A'), array('left' => 2, 'right' => 4, 'x' => 'B'), array('left' => 5, 'right' => 10, 'x' => 'C'), array('left' => 6, 'right' => 7, 'x' => 'D'), array('left' => 8, 'right' => 9, 'x' => 'E'), array('left' => 12, 'right' => 13, 'x' => 'F'), ); function createTree ($category, $left = 0, $right = null) { $tree = array(); foreach ($category as $cat => $data) { if ($data['left'] == $left + 1 && (is_null($right) || $data['right'] < $right)) { $tree[$cat] = createTree($category, $data['left'], $data['right']); $left = $data['right']; } } return $tree; } $tree = createTree ($category); print_r($tree);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [1] => Array ( ) [2] => Array ( [3] => Array ( ) [4] => Array ( ) ) ) [5] => Array ( ) )

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:
57.08 ms | 402 KiB | 8 Q