3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTree($treeByParent, $treeByCat, $id, $listed = []) { $gTree = []; $gTree[] = $id; if ( count($treeByCat[ $id ]) > 0 ) $gTree = array_merge( getTree($treeByParent, $treeByCat, $treeByCat[ $id ]), $gTree); if ( count($treeByParent[ $id ]) > 0 ) { foreach ($treeByParent[ $id ] as $cat) $gTree = array_merge( getTree($treeByParent, $treeByCat, $cat), $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.0140.00018.84
8.3.30.0120.00319.04
8.3.20.0050.00220.29
8.3.10.0040.00423.36
8.3.00.0080.00019.50
8.2.170.0140.00322.96
8.2.160.0140.00020.46
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00722.16
8.2.110.0070.00322.04
8.2.100.0080.00417.84
8.2.90.0080.00019.22
8.2.80.0000.00818.05
8.2.70.0090.00317.63
8.2.60.0050.00318.03
8.2.50.0040.00418.07
8.2.40.0060.00318.22
8.2.30.0040.00418.17
8.2.20.0000.00717.83
8.2.10.0050.00218.04
8.2.00.0080.00417.72
8.1.270.0050.00322.23
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0060.00323.86
8.1.230.0080.00318.99
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0090.00017.36
8.1.190.0050.00317.54
8.1.180.0060.00318.10
8.1.170.0060.00318.57
8.1.160.0030.00522.11
8.1.150.0000.00718.68
8.1.140.0000.00817.55
8.1.130.0030.00317.87
8.1.120.0030.00517.51
8.1.110.0030.00517.40
8.1.100.0030.00417.42
8.1.90.0030.00317.49
8.1.80.0030.00317.55
8.1.70.0000.00717.51
8.1.60.0030.00517.61
8.1.50.0040.00417.55
8.1.40.0000.00817.45
8.1.30.0080.00017.62
8.1.20.0050.00317.71
8.1.10.0050.00317.61
8.1.00.0080.00017.51
8.0.300.0040.00418.77
8.0.290.0070.00017.04
8.0.280.0030.00318.41
8.0.270.0050.00317.23
8.0.260.0030.00317.23
8.0.250.0000.00717.00
8.0.240.0030.00617.03
8.0.230.0030.00316.90
8.0.220.0000.00716.82
8.0.210.0000.00716.82
8.0.200.0030.00317.01
8.0.190.0030.00317.08
8.0.180.0070.00016.91
8.0.170.0060.00316.91
8.0.160.0000.00716.96
8.0.150.0040.00416.90
8.0.140.0070.00016.84
8.0.130.0000.00713.38
8.0.120.0080.00016.90
8.0.110.0040.00416.89
8.0.100.0040.00417.02
8.0.90.0040.00316.77
8.0.80.0060.00916.88
8.0.70.0000.00716.77
8.0.60.0040.00416.98
8.0.50.0040.00416.79
8.0.30.0130.00917.22
8.0.20.0150.00417.40
8.0.10.0070.00016.98
8.0.00.0090.00916.62
7.4.330.0050.00015.00
7.4.320.0000.00817.14
7.4.300.0020.00517.03
7.4.290.0000.01017.14
7.4.280.0000.00816.78
7.4.270.0000.00716.69
7.4.260.0050.00316.96
7.4.250.0000.00917.01
7.4.240.0030.00717.03
7.4.230.0040.00416.95
7.4.220.0110.01117.14
7.4.210.0090.01016.81
7.4.200.0030.00817.16
7.4.190.0060.00317.22
7.4.160.0130.00616.75
7.4.150.0160.01117.40
7.4.140.0190.01717.86
7.4.130.0170.01217.07
7.4.120.0220.01016.98
7.4.110.0200.01217.11
7.4.100.0440.00517.12
7.4.90.0070.01817.15
7.4.80.0170.01019.39
7.4.70.0150.00817.10
7.4.60.0120.00616.79
7.4.50.0070.00717.21
7.4.40.0130.00322.77
7.4.30.0180.01516.98
7.4.00.0070.01015.04
7.3.330.0030.00313.75
7.3.320.0030.00313.71
7.3.310.0030.00616.92
7.3.300.0000.00716.60
7.3.290.0230.00816.93
7.3.280.0150.01016.84
7.3.270.0100.01017.40
7.3.260.0220.00816.91
7.3.250.0170.01017.09
7.3.240.0240.01217.09
7.3.230.0240.01817.13
7.3.210.0250.02116.88
7.3.200.0180.00719.39
7.3.190.0200.00817.02
7.3.180.0120.00916.96
7.3.170.0100.01717.11
7.3.160.0170.00617.00
7.3.120.0060.00315.30
7.2.330.0230.00917.30
7.2.320.0160.01117.18
7.2.310.0100.01817.03
7.2.300.0100.01717.34
7.2.290.0110.01417.08
7.2.60.0080.00416.79
7.2.00.0080.00819.22
7.1.200.0110.00015.94
7.1.100.0060.00618.21
7.1.70.0000.01017.04
7.1.60.0130.01319.33
7.1.50.0260.01317.17
7.1.00.0070.07322.42
7.0.200.0410.01015.79
7.0.140.0130.06722.21
7.0.60.0170.07321.21
7.0.50.0070.05719.13
7.0.40.0030.04719.85
7.0.30.0370.08019.88
7.0.20.0430.07719.94
7.0.10.0130.08019.77
7.0.00.0100.04719.94
5.6.280.0000.08023.06
5.6.210.0170.07322.46
5.6.200.0070.08720.92
5.6.190.0100.03722.48
5.6.180.0170.10022.37
5.6.170.0200.03722.39
5.6.160.0100.05022.41
5.6.150.0000.07020.14
5.6.140.0130.07720.12
5.6.130.0100.07020.14
5.6.120.0130.04323.05
5.6.110.0100.04022.88
5.6.100.0070.08323.01
5.6.90.0070.04022.92
5.6.80.0130.07322.38
5.6.70.4570.04322.38
5.5.350.0130.06322.40
5.5.340.0130.06022.68
5.5.330.0200.07322.85
5.5.320.0100.09322.93
5.5.310.0070.07022.82
5.5.300.0330.05322.89
5.5.290.0230.05322.81
5.5.280.0270.05722.68
5.5.270.0270.05022.76
5.5.260.0200.08022.89
5.5.250.0230.05322.70
5.5.240.0100.05722.25
5.4.450.0230.05021.46
5.4.440.0070.09021.12
5.4.430.0230.07321.45
5.4.420.0170.05721.34
5.4.410.0170.08021.24
5.4.400.0100.06021.04
5.4.390.0100.06321.04
5.4.380.0200.08020.95
5.4.370.0100.06320.80
5.4.360.0170.06720.98
5.4.350.0200.04720.86
5.4.340.0100.05720.78
5.4.320.0230.05020.98
5.4.310.0100.05720.98
5.4.300.0130.08321.00
5.4.290.0130.05321.01
5.4.280.0230.07012.37
5.4.270.0080.05412.37
5.4.260.0140.06612.37
5.4.250.0090.05412.37
5.4.240.0200.04320.90
5.4.230.0080.07312.36
5.4.220.0090.07912.36
5.4.210.0100.05012.36
5.4.200.0070.06720.99
5.4.190.0090.05112.39
5.4.180.0070.04212.36
5.4.170.0060.04112.36
5.4.160.0100.04712.36
5.4.150.0070.03512.36
5.4.140.0110.03212.04
5.4.130.0100.04812.03
5.4.120.0170.05018.36
5.4.110.0060.03811.98
5.4.100.0090.03511.99
5.4.90.0060.03811.98
5.4.80.0070.03811.98
5.4.70.0050.04511.98
5.4.60.0090.04611.98
5.4.50.0100.03511.98
5.4.40.0060.03811.96
5.4.30.0080.04111.96
5.4.20.0100.03911.96
5.4.10.0080.04311.97
5.4.00.0060.03811.45
5.3.290.0040.04212.80
5.3.280.0000.06014.58
5.3.270.0130.07314.62
5.3.260.0170.04714.64
5.3.250.0070.05014.59
5.3.240.0100.05014.60
5.3.230.0070.07314.74
5.3.220.0070.05014.56
5.3.210.0000.06014.57
5.3.200.0000.06014.58
5.3.190.0100.05314.60
5.3.180.0130.06014.69
5.3.170.0030.05714.57
5.3.160.0100.04714.50
5.3.150.0170.04014.56
5.3.140.0000.05714.53
5.3.130.0070.07014.53
5.3.120.0130.05014.54
5.3.110.0100.05314.43
5.3.100.0170.05314.19
5.3.90.0100.04714.17
5.3.80.0070.05314.01
5.3.70.0030.06313.92
5.3.60.0030.05314.00
5.3.50.0030.05313.97
5.3.40.0030.05314.05
5.3.30.0230.05313.91
5.3.20.0100.06013.68
5.3.10.0100.04713.79
5.3.00.0170.04013.67
5.2.170.0030.04011.25
5.2.160.0100.06011.14
5.2.150.0130.04311.26
5.2.140.0000.05011.24
5.2.130.0130.05011.13
5.2.120.0030.04011.13
5.2.110.0170.04310.97
5.2.100.0100.03311.13
5.2.90.0030.06011.08
5.2.80.0000.04711.11
5.2.70.0030.04711.11
5.2.60.0070.03711.02
5.2.50.0030.04011.00
5.2.40.0070.03710.89
5.2.30.0100.03310.84
5.2.20.0100.03710.98
5.2.10.0070.03711.00
5.2.00.0130.03310.71
5.1.60.0070.04310.04
5.1.50.0000.04010.03
5.1.40.0030.0339.97
5.1.30.0130.04310.46
5.1.20.0070.05010.35
5.1.10.0100.03310.08
5.1.00.0070.03010.15
5.0.50.0030.0308.61
5.0.40.0030.0378.41
5.0.30.0070.0378.29
5.0.20.0070.0238.29
5.0.10.0030.0278.18
5.0.00.0000.0438.18
4.4.90.0030.0278.18
4.4.80.0030.0278.18
4.4.70.0100.0138.18
4.4.60.0070.0208.18
4.4.50.0000.0338.18
4.4.40.0070.0338.18
4.4.30.0000.0278.18
4.4.20.0100.0138.18
4.4.10.0070.0278.18
4.4.00.0030.0438.18
4.3.110.0070.0308.18
4.3.100.0100.0178.18
4.3.90.0000.0278.18
4.3.80.0000.0478.18
4.3.70.0000.0208.18
4.3.60.0000.0238.18
4.3.50.0030.0308.18
4.3.40.0070.0308.18
4.3.30.0000.0238.18
4.3.20.0000.0278.18
4.3.10.0000.0278.18
4.3.00.0300.01713.47

preferences:
41.99 ms | 400 KiB | 5 Q