3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $listed = []) { $gTree = []; $gTree[] = $treeByCat[ $id ]; if ( count($treeByParent[ $id ]) > 0) { foreach ($treeByParent[ $id ] as $cat) $gTree[] = $cat; } if ( count($treeByParent[ $treeByCat[ $id ] ]) > 0 ) $gTree[] = getTree($treeByParent, $treeByCat, $treeByCat[ $id ]); 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/qFpgo on line 7 Warning: Undefined array key 0 in /in/qFpgo on line 15 Warning: Undefined array key "" in /in/qFpgo on line 15 Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /in/qFpgo:15 Stack trace: #0 /in/qFpgo(15): getTree(Array, Array, 0) #1 /in/qFpgo(15): getTree(Array, Array, 1) #2 /in/qFpgo(15): getTree(Array, Array, 3) #3 /in/qFpgo(42): getTree(Array, Array, 4) #4 {main} thrown in /in/qFpgo on line 15
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:
68.3 ms | 401 KiB | 8 Q