3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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[$id]) > 0 ) 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, 3) );
Output for 5.4.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: 0 in /in/TZCMe on line 7 Notice: Undefined offset: 0 in /in/TZCMe on line 15 Notice: Undefined index: in /in/TZCMe on line 7 Notice: Undefined index: in /in/TZCMe on line 9 Notice: Undefined index: in /in/TZCMe on line 15 Array ( [0] => 1 [1] => 4 )
Output for hhvm-3.12.0
Notice: Undefined index: 0 in /in/TZCMe on line 7 Notice: Undefined index: 0 in /in/TZCMe on line 15 Notice: Undefined index: in /in/TZCMe on line 7 Notice: Undefined index: in /in/TZCMe on line 9 Notice: Undefined index: in /in/TZCMe on line 15 Array ( [0] => 1 [1] => 4 )
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/TZCMe on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/TZCMe on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/TZCMe on line 3
Process exited with code 255.