3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getTree($treeByParent, $treeByCat, $id, $lastId) { $gTree = []; if ($id != $lastId) { $gTree[] = $id; if ( isset($treeByCat[ $id ]) && count($treeByCat[ $id ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ], $id), $gTree); if ( isset($treeByParent[ $id ]) && count($treeByParent[ $id ]) > 0 ) { foreach ($treeByParent[ $id ] as $cat) $gTree = array_merge( getTree($treeByParent, $treeByCat, $cat, $id), $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 7.1.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function getTree(), 3 passed in /in/b35Gf on line 47 and exactly 4 expected in /in/b35Gf:3 Stack trace: #0 /in/b35Gf(47): getTree(Array, Array, 4) #1 {main} thrown in /in/b35Gf on line 3
Process exited with code 255.
Output for 7.0.14
Warning: Missing argument 4 for getTree(), called in /in/b35Gf on line 47 and defined in /in/b35Gf on line 3 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 262144 bytes) in /in/b35Gf on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.11
Warning: Missing argument 4 for getTree(), called in /in/b35Gf on line 47 and defined in /in/b35Gf on line 3 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 262144 bytes) in /in/b35Gf on line 15
Process exited with code 255.
Output for hhvm-3.13.2
Warning: getTree() expects exactly 4 parameters, 3 given in /in/b35Gf on line 6 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Assertion failure: /build/hhvm/src/hhvm-HHVM-3.13.2/hphp/runtime/base/runtime-error.cpp:48: void HPHP::raise_error(const string&): assertion `0' failed.
Process exited with code 134.
Output for hhvm-3.12.0
Warning: getTree() expects exactly 4 parameters, 3 given in /in/b35Gf on line 6 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Assertion failure: /build/hhvm/src/hhvm-HHVM-3.12.0/hphp/runtime/base/runtime-error.cpp:48: void HPHP::raise_error(const string&): assertion `0' failed.
Process exited with code 134.
Output for hhvm-3.10.0
Warning: getTree() expects exactly 4 parameters, 3 given in /in/b35Gf on line 6 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Fatal error: Stack overflow in /in/b35Gf on line 15
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Warning: Missing argument 4 for getTree(), called in /in/b35Gf on line 47 and defined in /in/b35Gf on line 3 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 72 bytes) in /in/b35Gf on line 9
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Warning: Missing argument 4 for getTree(), called in /in/b35Gf on line 47 and defined in /in/b35Gf on line 3 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 130968 bytes) in /in/b35Gf on line 11
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Warning: Missing argument 4 for getTree(), called in /in/b35Gf on line 47 and defined in /in/b35Gf on line 3 Notice: Undefined variable: lastId in /in/b35Gf on line 8 Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 130968 bytes) in /in/b35Gf on line 15
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/b35Gf on line 6
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/b35Gf on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/b35Gf on line 6
Process exited with code 255.