3v4l.org

run code in 300+ PHP versions simultaneously
<?php class category { public $name; public $subCats = array(); public function __construct($name = "") { $this->name = $name; } public function add_sub_cat($subCat) { array_push($this->subCats, $subCat); } } function tree_print($root_category) { $stack = array(array($root_category)); echo '<ul>'."\n"; while (count($stack)) { $category = array_shift($stack[count($stack)-1]); echo '<li><div id="category-name"><p>' . $category->name . '</p></div></li>'."\n"; echo '<ul>'."\n"; $stack[] = $category->subCats; while (count($stack) && count($stack[count($stack)-1]) == 0) { echo '</ul>'."\n"; array_pop($stack); } } } $x = new category('root'); $x->add_sub_cat(new category('foo')); $x->add_sub_cat(new category('bar')); $x->subCats[0]->add_sub_cat(new category('baz')); $x->subCats[1]->add_sub_cat(new category('baz2')); tree_print($x);
Output for git.master, git.master_jit, rfc.property-hooks
<ul> <li><div id="category-name"><p>root</p></div></li> <ul> <li><div id="category-name"><p>foo</p></div></li> <ul> <li><div id="category-name"><p>baz</p></div></li> <ul> </ul> </ul> <li><div id="category-name"><p>bar</p></div></li> <ul> <li><div id="category-name"><p>baz2</p></div></li> <ul> </ul> </ul> </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:
90.33 ms | 402 KiB | 8 Q