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.0110.09112.40
5.4.270.0090.05512.40
5.4.260.0050.06012.39
5.4.250.0090.05812.39
5.4.240.0050.05912.40
5.4.230.0070.05812.39
5.4.220.0090.05512.39
5.4.210.0150.05312.39
5.4.200.0070.05212.39
5.4.190.0060.05412.39
5.4.180.0150.05412.39
5.4.170.0070.05012.39
5.4.160.0100.04412.38
5.4.150.0110.04512.38
5.4.140.0060.05212.07
5.4.130.0050.04012.05
5.4.120.0060.03612.02
5.4.110.0070.03412.01
5.4.100.0060.03612.02
5.4.90.0070.05312.02
5.4.80.0070.05712.02
5.4.70.0060.05412.01
5.4.60.0070.03612.01
5.4.50.0090.03912.01
5.4.40.0130.03912.00
5.4.30.0080.03511.99
5.4.20.0070.03512.00
5.4.10.0100.03512.00
5.4.00.0040.04011.48
5.3.280.0020.04212.71
5.3.270.0040.04412.72
5.3.260.0070.03912.72
5.3.250.0050.04012.72
5.3.240.0080.03612.72
5.3.230.0110.04812.70
5.3.220.0060.04312.68
5.3.210.0060.04712.68
5.3.200.0060.05712.68
5.3.190.0080.05212.68
5.3.180.0030.04312.67
5.3.170.0060.04112.67
5.3.160.0100.04812.67
5.3.150.0110.04712.67
5.3.140.0080.04612.66
5.3.130.0060.05612.66
5.3.120.0110.04012.66
5.3.110.0050.04512.66
5.3.100.0090.03512.12
5.3.90.0090.03412.08
5.3.80.0100.03512.08
5.3.70.0070.03912.08
5.3.60.0070.04412.06
5.3.50.0100.04512.00
5.3.40.0080.05212.00
5.3.30.0070.05211.95
5.3.20.0090.03811.73
5.3.10.0060.04111.70
5.3.00.0060.03711.69
5.2.170.0070.0289.18
5.2.160.0080.0319.18
5.2.150.0060.0339.19
5.2.140.0080.0289.18
5.2.130.0040.0479.14
5.2.120.0040.0449.14
5.2.110.0120.0309.15
5.2.100.0070.0359.15
5.2.90.0090.0409.14
5.2.80.0100.0439.14
5.2.70.0060.0539.14
5.2.60.0050.0479.10
5.2.50.0050.0439.07
5.2.40.0080.0519.04
5.2.30.0090.0319.02
5.2.20.0100.0379.01
5.2.10.0050.0348.92
5.2.00.0060.0298.79
5.1.60.0060.0248.07
5.1.50.0050.0268.06
5.1.40.0050.0258.04
5.1.30.0080.0258.40
5.1.20.0030.0298.42
5.1.10.0030.0268.14
5.1.00.0030.0308.14
5.0.50.0030.0256.62
5.0.40.0040.0346.49
5.0.30.0050.0496.29
5.0.20.0030.0276.27
5.0.10.0030.0296.24
5.0.00.0020.0436.23
4.4.90.0030.0234.77
4.4.80.0050.0264.75
4.4.70.0050.0204.76
4.4.60.0020.0224.75
4.4.50.0040.0224.77
4.4.40.0050.0274.71
4.4.30.0030.0154.76
4.4.20.0020.0164.84
4.4.10.0030.0154.85
4.4.00.0040.0244.76
4.3.110.0030.0154.67
4.3.100.0050.0134.66
4.3.90.0030.0144.63
4.3.80.0030.0254.58
4.3.70.0030.0144.63
4.3.60.0040.0134.62
4.3.50.0030.0154.63
4.3.40.0040.0224.54
4.3.30.0030.0153.28
4.3.20.0010.0173.27
4.3.10.0010.0163.23
4.3.00.0030.01713.47

preferences:
141.37 ms | 1394 KiB | 7 Q