3v4l.org

run code in 500+ PHP versions simultaneously
<?php class CategoryTree { private $catTree = array(); public function addCategory($category, $parent) { if($parent == null){ if(count(array_column($this->catTree, 'category'), $category) > 0){ echo 'Duplicate category'; } } else{ } $temp = array("category" => $category,"parent" => $parent); array_push($this->catTree,$temp); } 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('C', 'A'); echo implode(',', $c->getChildren('A'));
Output for rfc.property-hooks, git.master, git.master_jit
Fatal error: Uncaught TypeError: count(): Argument #2 ($mode) must be of type int, string given in /in/BkvjC:9 Stack trace: #0 /in/BkvjC(9): count(Array, 'A') #1 /in/BkvjC(31): CategoryTree->addCategory('A', NULL) #2 {main} thrown in /in/BkvjC on line 9
Process exited with code 255.

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:
52.4 ms | 2455 KiB | 4 Q