3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( [ "name" => "cat1", "id" => "1", "parent" => "", ], [ "name" => "cat2", "id" => "2", "parent" => "", ], [ "name" => "subcat1", "id" => "6", "parent" => "1", ], [ "name" => "subsubcat1", "id" => "7", "parent" => "6", ], [ "name" => "subcat2", "id" => "5", "parent" => "2", ], ); function list_item($arr, $item) { echo "<li>{$item['name']}</li>\n"; // find any children $children = array_filter($arr, function ($i) use ($item) { return $i['parent'] == $item['id']; }); if (!empty($children)) { echo "<ul>\n"; foreach ($children as $child) { list_item($arr, $child); } echo "</ul>\n"; } } $parents = array_filter($arr, function ($item) { return !$item['parent'];}); echo "<ul>\n"; foreach ($parents as $parent) { list_item($arr, $parent); } echo "</ul>\n";
Output for git.master, git.master_jit, rfc.property-hooks
<ul> <li>cat1</li> <ul> <li>subcat1</li> <ul> <li>subsubcat1</li> </ul> </ul> <li>cat2</li> <ul> <li>subcat2</li> </ul> </ul>

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:
30.31 ms | 405 KiB | 5 Q