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; $childIds = array($id); $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'])); while ( count($childIds) > 0 ) { print_r($childIds); foreach($childIds as $child) { $children = array_keys($data, $child); foreach ($children as $ch) { $current = $data[$ch]; $child_id = $current === NULL ? "NULL" : $current; $tree['children'][] = $child_id; } $childIds = $children; } } echo "\n". 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)
8.3.60.0150.00016.48
8.3.50.0120.00917.98
8.3.40.0120.00318.94
8.3.30.0070.00719.08
8.3.20.0070.00020.25
8.3.10.0000.00823.68
8.3.00.0080.00019.38
8.2.180.0110.00718.13
8.2.170.0060.01022.96
8.2.160.0140.00320.45
8.2.150.0030.00524.18
8.2.140.0000.00824.66
8.2.130.0000.00926.16
8.2.120.0070.00022.08
8.2.110.0060.00320.41
8.2.100.0120.00017.88
8.2.90.0030.00519.25
8.2.80.0040.00417.97
8.2.70.0060.00317.50
8.2.60.0040.00418.05
8.2.50.0000.00818.07
8.2.40.0040.00418.03
8.2.30.0040.00418.05
8.2.20.0050.00217.82
8.2.10.0030.00518.20
8.2.00.0000.01017.61
8.1.270.0030.00523.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00324.02
8.1.230.0040.00717.52
8.1.220.0000.00817.76
8.1.210.0080.00018.77
8.1.200.0070.00317.35
8.1.190.0080.00017.52
8.1.180.0080.00018.10
8.1.170.0040.00418.71
8.1.160.0040.00422.07
8.1.150.0050.00318.66
8.1.140.0020.00517.54
8.1.130.0000.00817.83
8.1.120.0030.00317.48
8.1.110.0030.00517.51
8.1.100.0040.00417.50
8.1.90.0040.00417.37
8.1.80.0000.00717.46
8.1.70.0030.00317.38
8.1.60.0080.00017.62
8.1.50.0030.00617.36
8.1.40.0040.00417.38
8.1.30.0040.00417.66
8.1.20.0000.00717.56
8.1.10.0040.00417.49
8.1.00.0000.00817.54
8.0.300.0050.00318.77
8.0.290.0050.00316.63
8.0.280.0050.00218.37
8.0.270.0000.00717.15
8.0.260.0030.00317.26
8.0.250.0000.00716.95
8.0.240.0030.00316.94
8.0.230.0000.00716.97
8.0.220.0020.00516.92
8.0.210.0040.00416.78
8.0.200.0000.00616.95
8.0.190.0050.00317.00
8.0.180.0030.00316.96
8.0.170.0070.00016.83
8.0.160.0030.00316.86
8.0.150.0070.00016.74
8.0.140.0040.00416.84
8.0.130.0030.00313.43
8.0.120.0000.00816.91
8.0.110.0050.00316.89
8.0.100.0000.00716.96
8.0.90.0000.00716.74
8.0.80.0090.00616.90
8.0.70.0050.00316.79
8.0.60.0000.00716.97
8.0.50.0040.00416.93
8.0.30.0130.00717.15
8.0.20.0170.00817.40
8.0.10.0000.00917.05
8.0.00.0080.01016.80
7.4.330.0020.00215.00
7.4.320.0080.00016.43
7.4.300.0060.00016.48
7.4.290.0000.00716.61
7.4.280.0000.00716.61
7.4.270.0030.00316.51
7.4.260.0000.00716.50
7.4.250.0030.00316.59
7.4.240.0030.00516.51
7.4.230.0030.00316.72
7.4.220.0090.00916.65
7.4.210.0080.00716.56
7.4.200.0000.00816.60
7.4.190.0030.00516.70
7.4.160.0060.01016.51
7.4.150.0160.00317.40
7.4.140.0120.01017.86
7.4.130.0100.00616.54
7.4.120.0050.01216.54
7.4.110.0030.01416.68
7.4.100.0120.00616.63
7.4.90.0030.01316.38
7.4.80.0090.01319.39
7.4.70.0100.00616.57
7.4.60.0060.01216.56
7.4.50.0000.00816.57
7.4.40.0000.01322.77
7.4.30.0100.00716.63
7.4.00.0030.00714.86
7.3.330.0000.00613.36
7.3.320.0080.00013.38
7.3.310.0040.00416.24
7.3.300.0000.00716.43
7.3.290.0130.00016.42
7.3.280.0040.01316.37
7.3.270.0140.01017.40
7.3.260.0120.00416.60
7.3.250.0110.00916.45
7.3.240.0120.01216.66
7.3.230.0130.00316.46
7.3.210.0050.01116.47
7.3.200.0120.00619.39
7.3.190.0110.00716.37
7.3.180.0100.01316.57
7.3.170.0100.00616.35
7.3.160.0080.00816.48
7.3.120.0060.01214.67
7.2.330.0110.00616.59
7.2.320.0150.00916.48
7.2.310.0140.00816.79
7.2.300.0030.01916.48
7.2.290.0120.01216.41
7.2.60.0180.00716.98
7.2.50.0030.00917.15
7.1.200.0000.01215.62
7.1.100.0030.01018.16
7.1.70.0110.00517.04
7.1.60.0100.01019.33
7.1.50.0110.01116.98
7.1.00.0170.06022.48
7.0.200.0300.00715.03
7.0.140.0030.07321.93
7.0.60.0070.08719.95
7.0.50.0100.07017.75
7.0.40.0070.07020.11
7.0.30.0500.05320.32
7.0.20.0300.04720.23
7.0.10.0100.08320.12
7.0.00.0100.08020.33
5.6.280.0030.07320.83
5.6.210.0170.08020.74
5.6.200.0170.07318.15
5.6.190.0000.04720.57
5.6.180.0170.05020.77
5.6.170.0300.04720.51
5.6.160.0130.08020.54
5.6.150.0070.05318.17
5.6.140.0070.08718.15
5.6.130.0070.04318.18
5.6.120.0170.08021.19
5.6.110.0130.06721.11
5.6.100.0100.08020.90
5.6.90.0030.04321.02
5.6.80.0100.05320.30
5.6.70.4400.03020.55
5.5.350.0000.04320.46
5.5.340.0130.03018.00
5.5.330.0100.04720.45
5.5.320.0230.08320.27
5.5.310.0230.08320.34
5.5.300.0030.08717.96
5.5.290.0070.06017.98
5.5.280.0030.08720.86
5.5.270.0030.08720.66
5.5.260.0100.07320.81
5.5.250.0030.07020.72
5.5.240.0270.07020.16
5.4.450.0630.03719.18
5.4.440.1030.06319.71
5.4.430.0330.07019.33
5.4.420.0930.06319.30
5.4.410.0630.07019.42
5.4.400.0200.04718.98
5.4.390.0600.05018.87
5.4.380.0200.06318.76
5.4.370.0300.05318.63
5.4.360.0400.05318.79
5.4.350.0230.06318.71
5.4.340.0200.06718.79
5.4.320.0130.03712.52
5.4.310.0090.04412.52
5.4.300.0090.03612.52
5.4.290.0050.04412.52
5.4.280.0170.11512.39
5.4.270.0160.04212.38
5.4.260.0130.04912.38
5.4.250.0070.05812.39
5.4.240.0120.05212.38
5.4.230.0090.04512.38
5.4.220.0120.05612.37
5.4.210.0150.04812.38
5.4.200.0080.04212.38
5.4.190.0080.04012.37
5.4.180.0100.05012.38
5.4.170.0100.05612.38
5.4.160.0160.05112.38
5.4.150.0100.05012.37
5.4.140.0070.05512.05
5.4.130.0070.04812.04
5.4.120.0150.05412.00
5.4.110.0070.05212.00
5.4.100.0100.04712.00
5.4.90.0090.05612.00
5.4.80.0080.05912.00
5.4.70.0050.06711.99
5.4.60.0120.04712.00
5.4.50.0090.04311.99
5.4.40.0090.03511.98
5.4.30.0070.03511.98
5.4.20.0050.03711.98
5.4.10.0060.03511.98
5.4.00.0050.04811.47
5.3.290.0090.04412.80
5.3.280.0040.04112.71
5.3.270.0070.03912.72
5.3.260.0050.03912.72
5.3.250.0050.03912.72
5.3.240.0080.03612.71
5.3.230.0070.04012.71
5.3.220.0090.03512.68
5.3.210.0090.03712.68
5.3.200.0070.05512.68
5.3.190.0090.04912.68
5.3.180.0110.05212.67
5.3.170.0130.05812.67
5.3.160.0090.05412.68
5.3.150.0090.05312.67
5.3.140.0060.05512.66
5.3.130.0060.05712.66
5.3.120.0120.05212.66
5.3.110.0090.05212.66
5.3.100.0080.05012.12
5.3.90.0090.05712.09
5.3.80.0100.05412.07
5.3.70.0100.04812.07
5.3.60.0090.04812.06
5.3.50.0100.04212.00
5.3.40.0110.04812.00
5.3.30.0070.05311.95
5.3.20.0090.04811.74
5.3.10.0050.05111.71
5.3.00.0130.03811.69
5.2.170.0250.0409.19
5.2.160.0110.0369.18
5.2.150.0110.0579.19
5.2.140.0090.0339.18
5.2.130.0080.0289.14
5.2.120.0080.0299.14
5.2.110.0070.0309.14
5.2.100.0060.0299.14
5.2.90.0100.0429.14
5.2.80.0090.0339.14
5.2.70.0050.0349.14
5.2.60.0080.0309.10
5.2.50.0050.0349.07
5.2.40.0080.0319.04
5.2.30.0040.0339.01
5.2.20.0070.0339.01
5.2.10.0060.0298.93
5.2.00.0080.0328.78
5.1.60.0060.0348.07
5.1.50.0050.0328.07
5.1.40.0060.0248.04
5.1.30.0020.0288.40
5.1.20.0030.0288.42
5.1.10.0050.0258.14
5.1.00.0030.0278.14
5.0.50.0070.0176.62
5.0.40.0040.0206.48
5.0.30.0060.0306.29
5.0.20.0010.0236.26
5.0.10.0020.0236.24
5.0.00.0010.0346.23
4.4.90.0000.0194.77
4.4.80.0020.0174.76
4.4.70.0030.0174.76
4.4.60.0070.0134.75
4.4.50.0030.0174.77
4.4.40.0030.0344.71
4.4.30.0010.0204.75
4.4.20.0050.0204.84
4.4.10.0070.0144.85
4.4.00.0030.0254.76
4.3.110.0020.0164.66
4.3.100.0020.0184.67
4.3.90.0040.0154.63
4.3.80.0040.0244.59
4.3.70.0010.0174.63
4.3.60.0010.0174.63
4.3.50.0050.0144.63
4.3.40.0030.0254.54
4.3.30.0010.0173.29
4.3.20.0020.0163.26
4.3.10.0030.0153.23
4.3.00.0130.01713.47

preferences:
63.5 ms | 400 KiB | 5 Q