3v4l.org

run code in 300+ PHP versions simultaneously
<?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; } } function display_parent_nodes($data, $id) { $tree = array( "parents" => array(), "children" => array(), "full" => array() ); $current = $data[$id]; $parent_id = $current === NULL ? "NULL" : $current; $tree['parents'][] = $parent_id; while (isset($data[$parent_id])) { $current = $data[$parent_id]; $parent_id = $current === NULL ? "NULL" : $current; $tree['parents'][] = $parent_id; } echo implode(" > ", array_reverse($tree['parents'])); foreach ($childIds as $child_id) { $children = array_keys($data, $child) while (isset($data[$children])) { $current = $data[$children]; $child_id = $current === NULL ? "NULL" : $current; $tree['children'][] = $child_id; } } echo " > ". implode(" > ", $tree['children']); } $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( display_parent_nodes($treeByCat, 4) ); //print_r( getTree($treeByParent, $treeByCat, 4, 0) );

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.280.0070.04112.39
5.4.270.0090.04712.39
5.4.260.0090.04212.39
5.4.250.0080.03712.39
5.4.240.0100.03712.39
5.4.230.0120.04412.38
5.4.220.0130.05312.38
5.4.210.0050.05712.38
5.4.200.0070.05512.38
5.4.190.0070.05612.38
5.4.180.0050.05512.38
5.4.170.0130.06812.38
5.4.160.0090.07012.38
5.4.150.0090.03712.38
5.4.140.0080.04212.07
5.4.130.0080.04012.05
5.4.120.0070.03712.01
5.4.110.0070.03812.01
5.4.100.0050.04312.00
5.4.90.0050.04512.01
5.4.80.0140.03512.01
5.4.70.0110.05612.00
5.4.60.0110.05612.00
5.4.50.0080.05812.01
5.4.40.0220.08711.99
5.4.30.0140.04111.98
5.4.20.0050.04011.98
5.4.10.0070.04011.99
5.4.00.0070.03711.48
5.3.280.0090.04212.71
5.3.270.0080.06712.72
5.3.260.0110.06912.72
5.3.250.0110.04312.72
5.3.240.0080.05012.71
5.3.230.0060.05312.71
5.3.220.0120.07012.68
5.3.210.0110.05212.68
5.3.200.0060.05512.68
5.3.190.0150.07412.68
5.3.180.0090.04012.67
5.3.170.0090.04412.67
5.3.160.0100.05112.67
5.3.150.0070.05712.67
5.3.140.0070.04312.66
5.3.130.0080.04212.66
5.3.120.0190.07012.66
5.3.110.0130.05212.66
5.3.100.0100.06112.12
5.3.90.0080.03912.08
5.3.80.0140.04812.08
5.3.70.0090.06112.08
5.3.60.0160.07112.06
5.3.50.0100.06112.00
5.3.40.0110.05312.00
5.3.30.0110.05311.95
5.3.20.0080.05211.73
5.3.10.0100.05211.70
5.3.00.0080.05711.69

preferences:
141.14 ms | 1394 KiB | 7 Q