3v4l.org

run code in 300+ PHP versions simultaneously
<?php $categories = array( array( 'parent_id' => 0, 'categories_id' => 1, ), array( 'parent_id' => 0, 'categories_id' => 2, ), array( 'parent_id' => 1, 'categories_id' => 11, ), array( 'parent_id' => 1, 'categories_id' => 111, ), array( 'parent_id' => 2, 'categories_id' => 22, ), ); foreach ($categories as $category) { } function build($category, &$tree = array()) { if ($category['parent_id'] == 0) { $category = array( $category['categories_id'] => $category, ); $tree = array_merge($tree, $category); return $tree; } foreach ($tree as $cate_id => $cate) { if ($category['parent_id'] == $cate_id) { $tree[$cate_id]['childs'] = $category; } if (is_array($cate)) { return build($cate, $tree); } } return $tree; }
Output for git.master_jit, git.master, rfc.property-hooks

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:
78.85 ms | 401 KiB | 8 Q