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; } } $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( getTree($treeByParent, $treeByCat, 4) );

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.40.0120.00318.80
8.3.30.0090.00619.17
8.3.20.0050.00220.34
8.3.10.0080.00023.48
8.3.00.0080.00019.38
8.2.170.0120.00622.96
8.2.160.0110.00320.47
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0090.00926.16
8.2.120.0070.00022.34
8.2.110.0090.00022.08
8.2.100.0080.00417.72
8.2.90.0040.00419.04
8.2.80.0080.00017.97
8.2.70.0040.00417.49
8.2.60.0060.00317.80
8.2.50.0000.00818.07
8.2.40.0080.00018.22
8.2.30.0000.00718.14
8.2.20.0040.00417.70
8.2.10.0040.00417.97
8.2.00.0000.01017.66
8.1.270.0090.00022.04
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0000.00823.74
8.1.230.0110.00019.10
8.1.220.0030.00617.74
8.1.210.0040.00418.77
8.1.200.0060.00317.38
8.1.190.0000.00917.53
8.1.180.0040.00418.10
8.1.170.0050.00318.44
8.1.160.0040.00421.91
8.1.150.0040.00418.58
8.1.140.0030.00617.40
8.1.130.0030.00317.88
8.1.120.0000.00717.43
8.1.110.0050.00317.40
8.1.100.0030.00517.33
8.1.90.0040.00417.38
8.1.80.0000.00717.42
8.1.70.0040.00417.32
8.1.60.0000.00817.66
8.1.50.0030.00517.56
8.1.40.0030.00617.54
8.1.30.0000.00817.48
8.1.20.0000.00717.65
8.1.10.0000.00817.55
8.1.00.0050.00317.56
8.0.300.0040.00418.77
8.0.290.0040.00417.18
8.0.280.0070.00018.48
8.0.270.0070.00017.15
8.0.260.0000.00817.16
8.0.250.0000.00716.88
8.0.240.0020.00517.00
8.0.230.0000.00716.92
8.0.220.0060.00016.87
8.0.210.0020.00516.86
8.0.200.0000.00616.93
8.0.190.0070.00016.93
8.0.180.0040.00416.80
8.0.170.0000.00816.81
8.0.160.0000.00816.77
8.0.150.0030.00416.72
8.0.140.0050.00316.84
8.0.130.0030.00313.34
8.0.120.0040.00416.88
8.0.110.0040.00416.87
8.0.100.0000.00816.93
8.0.90.0000.00817.00
8.0.80.0030.01316.89
8.0.70.0050.00216.85
8.0.60.0040.00416.76
8.0.50.0080.00016.75
8.0.30.0110.00717.29
8.0.20.0090.00917.40
8.0.10.0040.00417.05
8.0.00.0100.00816.77
7.4.330.0050.00015.00
7.4.320.0030.00316.45
7.4.300.0060.00016.43
7.4.290.0000.00816.51
7.4.280.0000.00816.50
7.4.270.0080.00016.64
7.4.260.0030.00316.47
7.4.250.0080.00016.49
7.4.240.0040.00316.48
7.4.230.0030.00316.50
7.4.220.0100.00716.57
7.4.210.0070.01016.56
7.4.200.0000.00716.26
7.4.190.0070.00016.50
7.4.160.0120.00816.50
7.4.150.0140.00417.40
7.4.140.0070.01517.86
7.4.130.0080.00816.57
7.4.120.0100.01116.63
7.4.110.0040.01216.50
7.4.100.0030.01716.25
7.4.90.0070.01016.31
7.4.80.0120.00619.39
7.4.70.0090.00616.48
7.4.60.0130.00916.45
7.4.50.0050.00316.31
7.4.40.0090.00922.77
7.4.30.0090.00916.54
7.4.00.0130.00314.69
7.3.330.0000.00513.13
7.3.320.0030.00313.18
7.3.310.0000.00716.42
7.3.300.0000.00716.33
7.3.290.0030.01816.27
7.3.280.0080.00816.30
7.3.270.0080.00917.40
7.3.260.0190.00016.50
7.3.250.0090.01016.37
7.3.240.0060.01816.31
7.3.230.0180.00316.39
7.3.210.0060.01216.27
7.3.200.0110.01119.39
7.3.190.0220.00016.56
7.3.180.0120.00316.17
7.3.170.0090.00616.50
7.3.160.0080.00816.53
7.3.120.0000.00814.96
7.2.330.0090.00916.63
7.2.320.0220.00316.36
7.2.310.0130.00316.70
7.2.300.0040.01116.63
7.2.290.0030.01216.39
7.2.60.0000.01616.74
7.2.00.0100.00719.28
7.1.200.0090.00615.77
7.1.100.0000.01317.81
7.1.70.0000.01016.74
7.1.60.0030.02119.33
7.1.50.0110.00816.90
7.1.00.0000.08022.46
7.0.200.4590.00378.04
7.0.140.0130.08784.18
7.0.60.0330.09383.37
7.0.50.0270.10081.21
7.0.40.0030.08020.26
7.0.30.0370.09020.20
7.0.20.0400.05720.30
7.0.10.0100.10020.09
7.0.00.0170.09720.16
5.6.280.0170.12085.61
5.6.210.0300.06385.33
5.6.200.0270.13382.86
5.6.190.0130.07085.16
5.6.180.0370.05785.08
5.6.170.0370.10784.95
5.6.160.0270.07085.05
5.6.150.0230.12782.80
5.6.140.0230.06382.79
5.6.130.0400.08082.86
5.6.120.0270.06385.83
5.6.110.0370.05385.84
5.6.100.0500.09785.82
5.6.90.0200.09785.81
5.6.80.0200.13785.12
5.6.70.4470.06784.99
5.5.350.0470.12085.07
5.5.340.0270.11082.66
5.5.330.0270.06784.86
5.5.320.0400.10384.64
5.5.310.0570.05384.80
5.5.300.0330.11382.66
5.5.290.0170.06382.63
5.5.280.0330.07385.61
5.5.270.0270.06085.57
5.5.260.0300.11785.45
5.5.250.0230.12785.36
5.5.240.0470.11085.06
5.4.450.0500.11384.27
5.4.440.1130.16384.23
5.4.430.0770.09384.11
5.4.420.1270.09783.96
5.4.410.0670.09383.94
5.4.400.0770.10783.52
5.4.390.0530.11783.62
5.4.380.1100.11083.42
5.4.370.0600.12383.32
5.4.360.0530.11083.36
5.4.350.0900.11783.61
5.4.340.0630.10383.59
5.4.320.0220.06777.37
5.4.310.0310.05977.36
5.4.300.0220.06777.37
5.4.290.0250.07277.36
5.4.280.0380.10077.23
5.4.270.0350.07977.23
5.4.260.0420.09577.23
5.4.250.0530.10277.23
5.4.240.0570.18877.23
5.4.230.0350.07977.23
5.4.220.0290.11777.22
5.4.210.0380.07977.22
5.4.200.0620.11177.22
5.4.190.0370.10777.22
5.4.180.0610.17877.22
5.4.170.0790.18277.23
5.4.160.0790.15177.23
5.4.150.0580.13377.22
5.4.140.0700.15276.90
5.4.130.0290.10776.89
5.4.120.0520.11076.85
5.4.110.0580.09876.85
5.4.100.0480.11376.85
5.4.90.0550.12476.84
5.4.80.0410.13576.84
5.4.70.0480.14976.84
5.4.60.0440.11576.84
5.4.50.0540.15876.84
5.4.40.0430.10176.83
5.4.30.0430.12276.83
5.4.20.0490.10076.82
5.4.10.0300.08176.83
5.4.00.0390.10576.32
5.3.290.0050.05012.80
5.3.280.0080.06512.71
5.3.270.0080.05112.72
5.3.260.0100.04012.72
5.3.250.0120.04912.72
5.3.240.0160.05812.72
5.3.230.0080.04312.71
5.3.220.0100.04212.68
5.3.210.0050.04612.68
5.3.200.0120.04312.68
5.3.190.0070.05312.68
5.3.180.0100.05112.67
5.3.170.0070.03912.66
5.3.160.0110.04912.67
5.3.150.0100.05312.67
5.3.140.0070.03812.66
5.3.130.0090.04112.66
5.3.120.0080.04012.66
5.3.110.0120.05312.66
5.3.100.0070.04012.11
5.3.90.0090.04912.08
5.3.80.0040.04512.07
5.3.70.0090.04312.07
5.3.60.0080.03712.06
5.3.50.0060.03912.00
5.3.40.0110.03412.00
5.3.30.0080.03511.95
5.3.20.0070.03811.74
5.3.10.0070.03511.71
5.3.00.0080.03911.69
5.2.170.0090.0329.18
5.2.160.0090.0469.18
5.2.150.0110.0369.19
5.2.140.0060.0349.18
5.2.130.0070.0319.14
5.2.120.0060.0329.14
5.2.110.0080.0399.15
5.2.100.0060.0429.15
5.2.90.0060.0329.14
5.2.80.0020.0379.14
5.2.70.0070.0439.14
5.2.60.0080.0289.09
5.2.50.0080.0299.07
5.2.40.0080.0349.04
5.2.30.0040.0389.01
5.2.20.0090.0259.01
5.2.10.0050.0298.92
5.2.00.0060.0388.78
5.1.60.0060.0268.06
5.1.50.0120.0298.06
5.1.40.0080.0308.05
5.1.30.0050.0278.39
5.1.20.0070.0268.41
5.1.10.0040.0298.14
5.1.00.0050.0268.14
5.0.50.0060.0196.62
5.0.40.0020.0226.48
5.0.30.0070.0406.28
5.0.20.0010.0306.27
5.0.10.0050.0186.24
5.0.00.0070.0346.23
4.4.90.0040.0154.78
4.4.80.0040.0164.75
4.4.70.0020.0174.76
4.4.60.0020.0234.75
4.4.50.0030.0184.77
4.4.40.0060.0284.71
4.4.30.0020.0174.76
4.4.20.0040.0154.84
4.4.10.0020.0174.85
4.4.00.0050.0254.76
4.3.110.0040.0164.67
4.3.100.0030.0154.67
4.3.90.0060.0134.64
4.3.80.0020.0274.59
4.3.70.0030.0214.63
4.3.60.0040.0154.63
4.3.50.0030.0234.63
4.3.40.0010.0364.54
4.3.30.0020.0183.28
4.3.20.0040.0203.27
4.3.10.0030.0163.23
4.3.00.0000.01310.37

preferences:
36.19 ms | 400 KiB | 5 Q