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 ) { 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 " > ". 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.0090.00616.38
8.3.50.0100.01021.92
8.3.40.0120.00318.79
8.3.30.0100.00319.22
8.3.20.0080.00020.35
8.3.10.0000.00823.54
8.3.00.0040.00419.13
8.2.180.0130.00318.16
8.2.170.0070.00722.96
8.2.160.0100.00320.39
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0000.00722.34
8.2.110.0040.00422.11
8.2.100.0080.00417.84
8.2.90.0030.00519.21
8.2.80.0000.00817.97
8.2.70.0060.00317.62
8.2.60.0040.00418.05
8.2.50.0040.00418.07
8.2.40.0000.00818.22
8.2.30.0000.00718.06
8.2.20.0000.00817.68
8.2.10.0050.00318.14
8.2.00.0070.00417.76
8.1.280.0110.01125.92
8.1.270.0080.00022.11
8.1.260.0040.00426.35
8.1.250.0060.00328.09
8.1.240.0060.00323.91
8.1.230.0070.00418.97
8.1.220.0030.00517.74
8.1.210.0000.00818.77
8.1.200.0060.00317.13
8.1.190.0040.00417.50
8.1.180.0000.00818.10
8.1.170.0030.00518.59
8.1.160.0040.00422.03
8.1.150.0000.00718.57
8.1.140.0050.00217.43
8.1.130.0030.00317.75
8.1.120.0000.00717.48
8.1.110.0070.00317.36
8.1.100.0050.00217.37
8.1.90.0000.00717.38
8.1.80.0030.00317.49
8.1.70.0000.00717.31
8.1.60.0090.00017.55
8.1.50.0000.00917.55
8.1.40.0030.00617.52
8.1.30.0000.00817.61
8.1.20.0040.00417.66
8.1.10.0000.00717.59
8.1.00.0000.00817.45
8.0.300.0070.00018.77
8.0.290.0040.00417.15
8.0.280.0070.00018.52
8.0.270.0040.00417.27
8.0.260.0030.00317.18
8.0.250.0000.00716.87
8.0.240.0040.00416.96
8.0.230.0030.00316.91
8.0.220.0030.00316.90
8.0.210.0000.00816.86
8.0.200.0000.00716.96
8.0.190.0050.00216.99
8.0.180.0000.00716.89
8.0.170.0040.00416.93
8.0.160.0000.00716.98
8.0.150.0000.00716.86
8.0.140.0040.00416.92
8.0.130.0070.00013.33
8.0.120.0040.00416.75
8.0.110.0080.00016.83
8.0.100.0000.00816.97
8.0.90.0050.00216.78
8.0.80.0000.01616.96
8.0.70.0000.00716.77
8.0.60.0000.00816.94
8.0.50.0020.00516.86
8.0.30.0110.00817.15
8.0.20.0130.00617.40
8.0.10.0070.00017.07
8.0.00.0080.01216.85
7.4.330.0000.00515.09
7.4.320.0030.00316.52
7.4.300.0000.00616.47
7.4.290.0000.00816.59
7.4.280.0030.00316.65
7.4.270.0070.00016.62
7.4.260.0000.00716.61
7.4.250.0000.00716.52
7.4.240.0040.00316.47
7.4.230.0050.00216.44
7.4.220.0120.00416.66
7.4.210.0070.00916.59
7.4.200.0080.00016.61
7.4.190.0040.00416.69
7.4.160.0090.00616.57
7.4.150.0130.00717.40
7.4.140.0080.00817.86
7.4.130.0070.01016.58
7.4.120.0080.00816.46
7.4.110.0060.01516.52
7.4.100.0150.00916.59
7.4.90.0100.00716.38
7.4.80.0040.01419.39
7.4.70.0030.01216.36
7.4.60.0090.01116.59
7.4.50.0030.00316.38
7.4.40.0120.00322.77
7.4.30.0140.00316.40
7.4.00.0030.01014.94
7.3.330.0060.00013.31
7.3.320.0030.00313.41
7.3.310.0040.00416.25
7.3.300.0030.00316.32
7.3.290.0060.01416.37
7.3.280.0100.00916.36
7.3.270.0160.00317.40
7.3.260.0100.01016.45
7.3.250.0110.01016.37
7.3.240.0140.00716.40
7.3.230.0100.00716.44
7.3.210.0060.01016.49
7.3.200.0060.01619.39
7.3.190.0140.01416.55
7.3.180.0080.01116.42
7.3.170.0100.01016.53
7.3.160.0060.00916.58
7.3.120.0040.01114.96
7.3.10.0070.00716.46
7.3.00.0120.00616.26
7.2.330.0170.00016.84
7.2.320.0080.01316.84
7.2.310.0120.00616.55
7.2.300.0090.01616.71
7.2.290.0100.01216.80
7.2.130.0000.01416.94
7.2.120.0030.00916.54
7.2.110.0090.00616.50
7.2.100.0040.00816.83
7.2.90.0080.00816.88
7.2.80.0100.01016.62
7.2.70.0030.00617.04
7.2.60.0060.00916.79
7.2.50.0100.00516.88
7.2.40.0100.00316.91
7.2.30.0090.00416.98
7.2.20.0130.00816.82
7.2.10.0130.00516.31
7.2.00.0040.01217.96
7.1.250.0060.00615.63
7.1.100.0040.01118.13
7.1.70.0090.00616.94
7.1.60.0120.00619.33
7.1.50.0100.01316.98
7.1.00.0100.06722.54
7.0.200.0060.00615.02
7.0.140.0030.07322.18
7.0.60.0200.06019.85
7.0.50.0000.05017.88
7.0.40.0000.04720.13
7.0.30.0270.07020.26
7.0.20.0330.05020.22
7.0.10.0000.09320.33
7.0.00.0030.04320.27
5.6.280.0030.07020.94
5.6.210.0030.08720.56
5.6.200.0070.08718.20
5.6.190.0030.05020.61
5.6.180.0230.08020.33
5.6.170.0170.07020.44
5.6.160.0130.03720.48
5.6.150.0070.07018.29
5.6.140.0070.08018.18
5.6.130.0030.05718.15
5.6.120.0070.04321.00
5.6.110.0000.09021.01
5.6.100.0130.07320.97
5.6.90.0000.04320.99
5.6.80.0030.08720.39
5.6.70.0600.04020.41
5.5.350.0070.08720.35
5.5.340.0070.05018.09
5.5.330.0130.07320.26
5.5.320.0300.03720.42
5.5.310.0230.07320.24
5.5.300.0000.08017.98
5.5.290.0170.07017.98
5.5.280.0070.05320.89
5.5.270.0070.08720.81
5.5.260.0070.09020.80
5.5.250.0130.06720.65
5.5.240.0100.03720.20
5.4.450.0670.06719.48
5.4.440.0630.06319.62
5.4.430.0930.06719.55
5.4.420.0230.06019.34
5.4.410.0730.07019.50
5.4.400.0430.04019.02
5.4.390.1100.06019.38
5.4.380.0470.06718.54
5.4.370.0300.06318.66
5.4.360.0370.04318.60
5.4.350.0300.05718.75
5.4.340.0370.04718.79
5.4.320.0090.03312.51
5.4.310.0070.04512.51
5.4.300.0070.04012.52
5.4.290.0040.03912.51
5.4.280.0150.05212.38
5.4.270.0090.04112.38
5.4.260.0160.07412.38
5.4.250.0140.05112.38
5.4.240.0110.05112.38
5.4.230.0080.06612.38
5.4.220.0090.04112.38
5.4.210.0090.04112.38
5.4.200.0100.03812.37
5.4.190.0180.05412.37
5.4.180.0120.03712.37
5.4.170.0110.03812.38
5.4.160.0170.07612.38
5.4.150.0100.05612.37
5.4.140.0060.04112.05
5.4.130.0070.03912.04
5.4.120.0060.04012.00
5.4.110.0150.03412.00
5.4.100.0150.07512.00
5.4.90.0130.05311.99
5.4.80.0140.06712.00
5.4.70.0320.08612.00
5.4.60.0210.08212.00
5.4.50.0310.08212.00
5.4.40.0140.06211.98
5.4.30.0110.06211.98
5.4.20.0120.06211.98
5.4.10.0150.07411.98
5.4.00.0200.10411.47
5.3.290.0120.04312.80
5.3.280.0310.07612.71
5.3.270.0160.07212.72
5.3.260.0180.04412.72
5.3.250.0170.04912.72
5.3.240.0140.06212.72
5.3.230.0200.09612.71
5.3.220.0140.06312.68
5.3.210.0170.09612.68
5.3.200.0160.08412.68
5.3.190.0180.09112.68
5.3.180.0140.08012.67
5.3.170.0150.05512.66
5.3.160.0150.06912.67
5.3.150.0130.06112.67
5.3.140.0120.06112.66
5.3.130.0210.10012.66
5.3.120.0180.05712.66
5.3.110.0060.04712.65
5.3.100.0040.04212.12
5.3.90.0060.06812.08
5.3.80.0090.05212.07
5.3.70.0070.05312.07
5.3.60.0100.05312.07
5.3.50.0050.04312.00
5.3.40.0080.03912.00
5.3.30.0060.04111.95
5.3.20.0060.03611.73
5.3.10.0080.04211.71
5.3.00.0120.04411.69
5.2.170.0070.0329.18
5.2.160.0050.0349.18
5.2.150.0080.0349.18
5.2.140.0080.0359.18
5.2.130.0080.0329.14
5.2.120.0070.0389.14
5.2.110.0120.0469.15
5.2.100.0140.0339.15
5.2.90.0060.0309.14
5.2.80.0140.0329.14
5.2.70.0080.0319.14
5.2.60.0080.0299.09
5.2.50.0090.0299.07
5.2.40.0060.0329.04
5.2.30.0080.0329.02
5.2.20.0030.0359.00
5.2.10.0050.0408.92
5.2.00.0050.0328.79
5.1.60.0020.0388.07
5.1.50.0050.0358.07
5.1.40.0060.0378.04
5.1.30.0080.0458.40
5.1.20.0090.0418.41
5.1.10.0050.0438.14
5.1.00.0100.0358.15
5.0.50.0050.0306.61
5.0.40.0080.0276.48
5.0.30.0040.0456.28
5.0.20.0070.0256.26
5.0.10.0070.0266.25
5.0.00.0020.0416.23
4.4.90.0090.0244.78
4.4.80.0060.0274.75
4.4.70.0040.0454.75
4.4.60.0090.0224.75
4.4.50.0060.0234.77
4.4.40.0050.0354.71
4.4.30.0020.0204.76
4.4.20.0060.0144.84
4.4.10.0060.0144.85
4.4.00.0100.0564.76
4.3.110.0030.0204.67
4.3.100.0000.0224.66
4.3.90.0020.0234.63
4.3.80.0050.0334.58
4.3.70.0040.0234.63
4.3.60.0040.0244.63
4.3.50.0040.0244.63
4.3.40.0020.0374.54
4.3.30.0030.0243.28
4.3.20.0030.0173.27
4.3.10.0050.0203.23
4.3.00.0230.01310.37

preferences:
36.09 ms | 401 KiB | 5 Q