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.60.0090.00616.75
8.3.50.0100.00822.04
8.3.40.0140.00718.62
8.3.30.0000.01819.22
8.3.20.0000.00720.34
8.3.10.0040.00423.64
8.3.00.0060.00319.26
8.2.180.0120.00318.31
8.2.170.0140.00022.96
8.2.160.0080.00520.52
8.2.150.0070.00024.18
8.2.140.0040.00424.66
8.2.130.0090.00626.16
8.2.120.0050.00222.25
8.2.110.0030.00622.14
8.2.100.0060.00617.91
8.2.90.0000.00819.22
8.2.80.0050.00317.97
8.2.70.0060.00317.63
8.2.60.0030.00617.68
8.2.50.0030.00518.07
8.2.40.0000.00818.22
8.2.30.0040.00417.89
8.2.20.0000.00817.58
8.2.10.0040.00418.08
8.2.00.0030.00617.73
8.1.280.0110.00725.92
8.1.270.0070.00022.19
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0030.00623.96
8.1.230.0080.00319.09
8.1.220.0080.00017.74
8.1.210.0040.00418.77
8.1.200.0040.00417.35
8.1.190.0040.00417.43
8.1.180.0040.00418.10
8.1.170.0080.00018.57
8.1.160.0000.00721.84
8.1.150.0000.00718.54
8.1.140.0040.00417.39
8.1.130.0030.00317.71
8.1.120.0000.00717.39
8.1.110.0000.00817.29
8.1.100.0040.00417.23
8.1.90.0000.00717.38
8.1.80.0070.00017.37
8.1.70.0000.00717.36
8.1.60.0000.00717.59
8.1.50.0000.00817.45
8.1.40.0030.00617.54
8.1.30.0030.00617.61
8.1.20.0000.00717.55
8.1.10.0000.00817.59
8.1.00.0040.00417.47
8.0.300.0000.00818.77
8.0.290.0000.00817.05
8.0.280.0070.00018.37
8.0.270.0000.00717.20
8.0.260.0030.00317.20
8.0.250.0070.00016.85
8.0.240.0070.00016.88
8.0.230.0000.00716.86
8.0.220.0000.00816.89
8.0.210.0000.00716.88
8.0.200.0030.00316.85
8.0.190.0030.00516.93
8.0.180.0070.00016.92
8.0.170.0040.00416.97
8.0.160.0080.00016.85
8.0.150.0040.00416.82
8.0.140.0040.00416.77
8.0.130.0000.00613.32
8.0.120.0000.00816.87
8.0.110.0000.00816.90
8.0.100.0000.00716.75
8.0.90.0050.00316.95
8.0.80.0090.00616.96
8.0.70.0000.00716.93
8.0.60.0070.00016.81
8.0.50.0000.00716.88
8.0.30.0120.00717.12
8.0.20.0120.00817.40
8.0.10.0080.00017.04
8.0.00.0140.00516.71
7.4.330.0060.00015.00
7.4.320.0070.00016.53
7.4.300.0000.00616.63
7.4.290.0000.00716.54
7.4.280.0040.00416.44
7.4.270.0040.00416.47
7.4.260.0030.00316.61
7.4.250.0000.00716.38
7.4.240.0040.00316.56
7.4.230.0000.00616.35
7.4.220.0070.01016.39
7.4.210.0050.01316.50
7.4.200.0000.00716.35
7.4.190.0070.00016.58
7.4.160.0090.00616.51
7.4.150.0130.00317.40
7.4.140.0140.00717.86
7.4.130.0110.00616.68
7.4.120.0080.00816.43
7.4.110.0100.00716.48
7.4.100.0060.01616.66
7.4.90.0150.00416.47
7.4.80.0030.01419.39
7.4.70.0140.00216.52
7.4.60.0140.00316.51
7.4.50.0040.00416.53
7.4.40.0130.00022.77
7.4.30.0110.00416.65
7.4.00.0030.01315.00
7.3.330.0000.00613.30
7.3.320.0000.00613.30
7.3.310.0040.00416.34
7.3.300.0070.00016.34
7.3.290.0040.01216.27
7.3.280.0080.01016.27
7.3.270.0100.00717.40
7.3.260.0150.00316.37
7.3.250.0090.00916.50
7.3.240.0090.01316.48
7.3.230.0070.01416.39
7.3.210.0040.01816.21
7.3.200.0060.01319.39
7.3.190.0060.01316.31
7.3.180.0080.00816.51
7.3.170.0100.00616.41
7.3.160.0090.00616.53
7.3.120.0030.01314.82
7.2.330.0090.00916.72
7.2.320.0130.00916.69
7.2.310.0120.00616.54
7.2.300.0200.00316.65
7.2.290.0080.00816.43
7.2.60.0070.00716.82
7.2.00.0120.00619.39
7.1.200.0070.00715.53
7.1.100.0090.00318.13
7.1.70.0030.00516.74
7.1.60.0120.01219.33
7.1.50.0000.01016.66
7.1.00.0070.07322.43
7.0.201.4980.02077.76
7.0.140.0030.09784.21
7.0.110.6100.05783.29
7.0.100.4270.05083.33
7.0.90.4830.05383.45
7.0.80.6830.04083.33
7.0.70.5870.05083.46
7.0.60.6230.05783.39
7.0.51.0300.09383.66
7.0.40.0100.08020.07
7.0.30.0130.10019.97
7.0.20.0100.11020.02
7.0.10.0170.09719.97
7.0.00.0070.10719.97
5.6.280.0270.11085.62
5.6.260.0230.06785.31
5.6.250.0200.06785.34
5.6.240.0300.06085.29
5.6.230.0170.07085.21
5.6.220.0130.06785.33
5.6.210.0230.04785.05
5.6.200.0230.11085.74
5.6.190.0270.09785.68
5.6.180.0270.07785.68
5.6.170.0270.10085.64
5.6.160.0270.10785.75
5.6.150.0300.11085.93
5.6.140.0330.09385.71
5.6.130.0270.11385.87
5.6.120.0170.11785.61
5.6.110.0370.10385.77
5.6.100.0270.11085.74
5.6.90.0400.11085.79
5.6.80.0430.10085.04
5.6.70.0230.06385.00
5.6.60.0330.11085.22
5.6.50.0400.09385.18
5.6.40.0370.10785.11
5.6.30.0400.09785.22
5.6.20.0170.09784.95
5.6.10.0370.10085.06
5.6.00.0370.09785.29
5.5.380.0300.04085.23
5.5.370.0230.06084.91
5.5.360.0070.08385.19
5.5.350.0230.06085.11
5.5.340.0270.11085.44
5.5.330.0200.10385.45
5.5.320.0270.10785.70
5.5.310.0470.10085.36
5.5.300.0330.09385.36
5.5.290.0170.12785.60
5.5.280.0170.11385.55
5.5.270.0370.11085.46
5.5.260.0330.11785.52
5.5.250.0300.07785.25
5.5.240.0270.11384.79
5.5.230.0330.11385.05
5.5.220.0230.10385.00
5.5.210.0300.09784.94
5.5.200.0300.08084.98
5.5.190.0470.08084.95
5.5.180.0330.06784.75
5.5.160.0400.08784.75
5.5.150.0300.11384.81
5.5.140.0370.10084.70
5.5.130.0300.10084.87
5.5.120.0270.08385.02
5.5.110.0270.09784.81
5.5.100.0030.13384.89
5.5.90.0330.05384.70
5.5.80.0270.11084.64
5.5.70.0470.09784.69
5.5.60.0330.11084.92
5.5.50.0230.11084.67
5.5.40.0230.09084.63
5.5.30.0430.08784.79
5.5.20.0270.11084.91
5.5.10.0400.09784.71
5.5.00.0370.09384.68
5.4.450.0230.10384.00
5.4.440.0400.11084.22
5.4.430.0330.10783.91
5.4.420.0300.05784.31
5.4.410.0230.11083.87
5.4.400.0270.11383.99
5.4.390.0470.09383.59
5.4.380.0330.10783.99
5.4.370.0200.10383.62
5.4.360.0130.13383.99
5.4.350.0300.11383.67
5.4.340.0230.10783.67
5.4.320.0200.08783.59
5.4.310.0270.11083.59
5.4.300.0300.09383.63
5.4.290.0170.12083.67
5.4.280.0270.11083.83
5.4.270.0300.10383.67
5.4.260.0400.04783.64
5.4.250.0230.12083.67
5.4.240.0230.10783.71
5.4.230.0430.09783.62
5.4.220.0300.10783.80
5.4.210.0400.08383.71
5.4.200.0300.07383.66
5.4.190.0270.10783.63
5.4.180.0370.08783.83
5.4.170.0200.08383.73
5.4.160.0370.10083.88
5.4.150.0530.11783.70
5.4.140.0270.10781.09
5.4.130.0200.08781.17
5.4.120.0370.08380.96
5.4.110.0330.10381.10
5.4.100.0370.08781.05
5.4.90.0300.10381.20
5.4.80.0300.10080.93
5.4.70.0270.08381.09
5.4.60.0270.10781.03
5.4.50.0300.09781.14
5.4.40.0270.10081.16
5.4.30.0370.09381.08
5.4.20.0230.11081.16
5.4.10.0270.10380.99
5.4.00.0200.12080.63
5.3.290.0070.07314.64
5.3.280.0030.06314.61
5.3.270.0100.07014.60
5.3.260.0030.07714.75
5.3.250.0030.07314.71
5.3.240.0130.07014.61
5.3.230.0230.05714.61
5.3.220.0070.07714.70
5.3.210.0030.08314.66
5.3.200.0070.07014.55
5.3.190.0000.05014.43
5.3.180.0070.08014.57
5.3.170.0070.05714.54
5.3.160.0030.06014.65
5.3.150.0100.06714.43
5.3.140.0030.07014.52
5.3.130.0070.06314.56
5.3.120.0000.08314.68
5.3.110.0130.06314.63
5.3.100.0100.07014.18
5.3.90.0130.07014.17
5.3.80.0200.05314.10
5.3.70.0030.07713.96
5.3.60.0100.04013.98
5.3.50.0000.07013.94
5.3.40.0030.07314.01
5.3.30.0130.06713.93
5.3.20.0070.06713.78
5.3.10.0030.07013.67
5.3.00.0030.07313.63
5.2.170.0100.06011.72
5.2.160.0070.03311.72
5.2.150.0100.05311.72
5.2.140.0030.06711.72
5.2.130.0100.05311.72
5.2.120.0030.04011.72
5.2.110.0030.06311.72
5.2.100.0070.05311.72
5.2.90.0030.03011.72
5.2.80.0030.04711.72
5.2.70.0070.02711.72
5.2.60.0030.05311.72
5.2.50.0070.05711.72
5.2.40.0030.06011.72
5.2.30.0070.06011.72
5.2.20.0070.06311.72
5.2.10.0100.02711.72
5.2.00.0130.05711.72
5.1.60.0030.05311.72
5.1.50.0100.03311.72
5.1.40.0070.05311.72
5.1.30.0030.05011.72
5.1.20.0030.05711.72
5.1.10.0030.04311.72
5.1.00.0100.02711.72
5.0.50.0000.05011.72
5.0.40.0030.04311.72
5.0.30.0030.06311.72
5.0.20.0070.04011.72
5.0.10.0000.04711.72
5.0.00.0000.06311.72
4.4.90.0030.01311.72
4.4.80.0000.03711.72
4.4.70.0000.03711.72
4.4.60.0030.01711.72
4.4.50.0070.02711.72
4.4.40.0070.04711.72
4.4.30.0030.03311.72
4.4.20.0030.03011.72
4.4.10.0070.03011.72
4.4.00.0000.06011.72
4.3.110.0000.02011.72
4.3.100.0030.03311.72
4.3.90.0030.03311.72
4.3.80.0000.04311.72
4.3.70.0000.03011.72
4.3.60.0030.02711.72
4.3.50.0030.03311.72
4.3.40.0070.04711.72
4.3.30.0000.03011.72
4.3.20.0000.03311.72
4.3.10.0030.02011.72
4.3.00.0000.03711.72

preferences:
33.65 ms | 401 KiB | 5 Q