3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $links = array( null => array(1, 2, 3, 4, 5), 2 => array(6, 7, 8, 9), 3 => array(10, 11), 10 => array(12), 12 => array(13) ); $nodes = array( 1 => array( "title" => 1, ), 2 => array( "title" => 2, ), 3 => array( "title" => 3, ), 4 => array( "title" => 4, ), 5 => array( "title" => 5, ), 6 => array( "title" => 6, ), 7 => array( "title" => 7, ), 8 => array( "title" => 8, ), 9 => array( "title" => 9, ), 10 => array( "title" => 10, ), 11 => array( "title" => 11, ), 12 => array( "title" => 12, ), 13 => array( "title" => 13, ), ); function f($node, $nodes, $links) { if (!isset($nodes[$node]["children"])) { $nodes[$node]["children"] = array(); } if (isset($links[$node])) { foreach($links[$node] as $child) { array_push($nodes[$node]["children"], f($child)); } } return $nodes[$node]; } f(null); print_r($nodes[null]["children"]);
based on 9dHvS
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function f(), 1 passed in /in/M0skj on line 68 and exactly 3 expected in /in/M0skj:53 Stack trace: #0 /in/M0skj(68): f(NULL) #1 {main} thrown in /in/M0skj on line 53
Process exited with code 255.
Output for 5.3.17 - 7.0.20
Warning: Missing argument 2 for f(), called in /in/M0skj on line 68 and defined in /in/M0skj on line 53 Warning: Missing argument 3 for f(), called in /in/M0skj on line 68 and defined in /in/M0skj on line 53 Notice: Undefined index: in /in/M0skj on line 70