3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $listed = []) { $gTree = []; $gTree[] = $id; if ( count($treeByCat[ $id ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ]), $gTree); if ( count($treeByParent[ $id ]) > 0 ) { foreach ($treeByParent[ $id ] as $cat) $gTree = array_merge( getTree($treeByParent, $treeByCat, $cat), $gTree); } return $gTree; } $treeByParent = array( 0 => array(1, 2), 1 => array(3, 7), 3 => array(4), 4 => array(5), 5 => array(6, 8) ); $treeByCat = array( 1 => 0, 2 => 0, 3 => 1, 7 => 1, 4 => 3, 5 => 4, 6 => 5, 8 => 5 ); print_r( getTree($treeByParent, $treeByCat, 4) );
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, int given in /in/re9IK:9 Stack trace: #0 /in/re9IK(45): getTree(Array, Array, 4) #1 {main} thrown in /in/re9IK 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:
41.78 ms | 401 KiB | 8 Q