3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CategoryTree { private $catTree = array(); public function addCategory($category, $parent) { if($parent == null){ //echo count(array_column($this->catTree, 'category')); if(count(array_column($this->catTree, 'category', $category)) > 0){ echo 'Duplicate category'; } else{ $temp = array("category" => $category,"parent" => $parent); array_push($this->catTree,$temp); } } else{ echo count(array_column($this->catTree, 'parent', $parent)); } } public function getChildren($parent) { $that = $this; $keys = array_keys(array_column($this->catTree, 'parent'), $parent); return array_map(function($k) use ($that){return $that->catTree[$k]['category'];}, $keys); } } // For testing purposes (do not submit uncommented): $c = new CategoryTree; $c->addCategory('A', null); $c->addCategory('A', null); $c->addCategory('B', 'A'); $c->addCategory('B', 'D'); $c->addCategory('C', 'A'); echo implode(',', $c->getChildren('A'));
Output for git.master, git.master_jit, rfc.property-hooks
Duplicate category111

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