3v4l.org

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