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'])); global $data, $index; $parent_id = $parent_id === NULL ? "NULL" : $parent_id; if (isset($index[$parent_id])) { foreach ($index[$parent_id] as $id) { $children[] = $id; $children = array_merge($children, get_child_nodes2($id)); } } 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.0040.04312.39
5.4.270.0100.03812.39
5.4.260.0030.04212.39
5.4.250.0060.04012.39
5.4.240.0100.04312.39
5.4.230.0060.03912.38
5.4.220.0080.03712.38
5.4.210.0070.04212.38
5.4.200.0090.04612.38
5.4.190.0060.06012.38
5.4.180.0150.07512.38
5.4.170.0090.05812.38
5.4.160.0080.03912.38
5.4.150.0090.04712.37
5.4.140.0050.04012.06
5.4.130.0060.04112.04
5.4.120.0090.04112.01
5.4.110.0060.04512.01
5.4.100.0100.06512.00
5.4.90.0110.05512.00
5.4.80.0090.05712.01
5.4.70.0080.05212.01
5.4.60.0130.05712.00
5.4.50.0090.05812.00
5.4.40.0120.05711.99
5.4.30.0100.05811.98
5.4.20.0190.07011.98
5.4.10.0090.05411.99
5.4.00.0130.07011.48
5.3.280.0080.05812.71
5.3.270.0140.07912.73
5.3.260.0150.06712.72
5.3.250.0080.06312.72
5.3.240.0110.04812.72
5.3.230.0140.07212.71
5.3.220.0130.05612.68
5.3.210.0110.05712.68
5.3.200.0080.07512.68
5.3.190.0150.05112.68
5.3.180.0060.06312.67
5.3.170.0120.09212.67
5.3.160.0060.05912.67
5.3.150.0090.06112.68
5.3.140.0150.05512.66
5.3.130.0060.04812.66
5.3.120.0080.04312.66
5.3.110.0050.04712.66
5.3.100.0060.04312.12
5.3.90.0120.03712.09
5.3.80.0090.03612.08
5.3.70.0050.04212.07
5.3.60.0090.03812.07
5.3.50.0110.03712.00
5.3.40.0060.04112.00
5.3.30.0090.03511.95
5.3.20.0080.04511.74
5.3.10.0130.04611.70
5.3.00.0110.04611.69

preferences:
158.82 ms | 1394 KiB | 7 Q