3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tree = array( 1 => array( 'parent_id' => null, 'name' => 'root', 'depth' => 0, ), 11 => array( 'parent_id' => 1, 'name' => 'a', 'depth' => 1, ), 12 => array( 'parent_id' => 1, 'name' => 'b', 'depth' => 1, ), 111 => array( 'parent_id' => 11, 'name' => 'aa', 'depth' => 2, ), 2 => array( 'parent_id' => null, 'name' => 'other root', 'depth' => 0, ) ); foreach ($tree as $key => &$sub) { if (isset($sub['parent_id'])) { $array[$sub['parent_id']]['children'][$key] = &$sub; } } unset($sub); // unset the reference to make sure to not overwrite it later... // now remove the entries with parents foreach ($array as $key => $sub) { if (isset($sub['parent_id'])) unset($array[$key]); } var_dump($array);

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.0120.00318.43
8.3.50.0150.00521.14
8.3.40.0090.00618.94
8.3.30.0100.00320.34
8.3.20.0060.00320.36
8.3.10.0040.00421.07
8.3.00.0080.00023.48
8.2.180.0120.00316.50
8.2.170.0140.00022.96
8.2.160.0060.01220.39
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0000.00826.16
8.2.120.0000.00821.06
8.2.110.0050.00519.45
8.2.100.0040.00818.03
8.2.90.0040.00419.30
8.2.80.0000.00818.16
8.2.70.0000.00817.50
8.2.60.0070.00317.93
8.2.50.0090.00018.07
8.2.40.0050.00518.21
8.2.30.0040.00419.43
8.2.20.0040.00417.77
8.2.10.0040.00717.73
8.2.00.0040.00417.79
8.1.280.0150.00025.92
8.1.270.0070.00023.99
8.1.260.0000.00826.35
8.1.250.0050.00328.09
8.1.240.0120.00022.45
8.1.230.0040.00720.72
8.1.220.0090.00018.77
8.1.210.0030.00518.95
8.1.200.0040.00417.35
8.1.190.0040.00417.66
8.1.180.0050.00318.10
8.1.170.0040.00418.61
8.1.160.0040.00418.80
8.1.150.0000.00818.55
8.1.140.0040.00417.45
8.1.130.0040.00417.74
8.1.120.0000.00717.36
8.1.110.0040.00417.34
8.1.100.0040.00417.43
8.1.90.0000.00717.49
8.1.80.0070.00017.34
8.1.70.0000.00817.45
8.1.60.0000.00817.55
8.1.50.0000.00717.46
8.1.40.0050.00317.54
8.1.30.0030.00617.63
8.1.20.0040.00417.50
8.1.10.0040.00417.53
8.1.00.0000.00717.37
8.0.300.0040.00420.02
8.0.290.0040.00417.18
8.0.280.0050.00218.35
8.0.270.0030.00317.17
8.0.260.0040.00416.73
8.0.250.0040.00417.00
8.0.240.0080.00316.96
8.0.230.0030.00316.86
8.0.220.0060.00016.77
8.0.210.0040.00416.84
8.0.200.0030.00316.99
8.0.190.0000.00816.96
8.0.180.0050.00216.96
8.0.170.0000.00716.83
8.0.160.0080.00016.85
8.0.150.0000.00716.83
8.0.140.0000.00816.91
8.0.130.0000.00713.27
8.0.120.0040.00416.85
8.0.110.0070.00016.95
8.0.100.0050.00316.88
8.0.90.0020.00516.80
8.0.80.0000.01516.84
8.0.70.0050.00217.00
8.0.60.0040.00416.76
8.0.50.0040.00416.77
8.0.30.0160.00717.00
8.0.20.0070.01317.40
8.0.10.0040.00416.97
8.0.00.0130.01316.61
7.4.330.0030.00316.83
7.4.320.0030.00316.55
7.4.300.0000.00616.55
7.4.290.0030.00316.58
7.4.280.0000.00716.45
7.4.270.0000.00716.58
7.4.260.0080.00013.26
7.4.250.0000.00716.57
7.4.240.0080.00016.47
7.4.230.0040.00416.67
7.4.220.0140.00416.49
7.4.210.0050.00916.55
7.4.200.0030.00316.63
7.4.190.0020.00516.69
7.4.160.0140.00316.47
7.4.150.0120.00617.40
7.4.140.0090.00917.86
7.4.130.0100.01016.60
7.4.120.0050.01216.59
7.4.110.0110.01416.48
7.4.100.0110.00816.45
7.4.90.0140.01016.31
7.4.80.0190.00619.39
7.4.70.0100.00716.43
7.4.60.0060.01216.36
7.4.50.0000.00816.60
7.4.40.0130.00322.77
7.4.30.0170.00016.32
7.4.00.0000.01614.84
7.3.330.0050.00013.25
7.3.320.0000.00513.16
7.3.310.0000.00816.17
7.3.300.0020.00516.36
7.3.290.0040.01116.35
7.3.280.0110.00716.35
7.3.270.0040.01517.40
7.3.260.0130.00918.24
7.3.250.0100.00916.53
7.3.240.0070.01316.69
7.3.230.0180.00316.55
7.3.210.0090.00916.45
7.3.200.0110.00819.39
7.3.190.0080.00916.69
7.3.180.0080.00916.48
7.3.170.0030.01316.42
7.3.160.0060.01316.67
7.3.120.0150.00014.75
7.3.10.0100.00316.52
7.3.00.0040.00416.59
7.2.330.0160.00216.69
7.2.320.0120.00616.63
7.2.310.0080.00816.73
7.2.300.0110.00716.90
7.2.290.0100.00716.73
7.2.130.0040.00816.93
7.2.120.0130.00016.73
7.2.110.0140.00016.74
7.2.100.0060.00317.13
7.2.90.0000.01417.20
7.2.80.0040.00417.00
7.2.70.0060.00616.84
7.2.60.0070.00316.97
7.2.50.0090.00616.98
7.2.40.0070.00416.96
7.2.30.0100.00716.89
7.2.20.0060.00616.80
7.2.10.0070.00717.06
7.2.00.0080.00618.27
7.1.250.0100.00315.91
7.1.200.0170.00615.65
7.1.100.0040.00818.05
7.1.70.0030.00716.89
7.1.60.0100.01019.17
7.1.50.0110.01416.86
7.1.00.0030.05022.58
7.0.200.0000.00716.67
7.0.140.0030.07322.04
7.0.100.0070.04720.00
7.0.90.0070.07020.15
7.0.80.0100.04719.93
7.0.70.0130.07320.00
7.0.60.0070.08319.98
7.0.50.0130.07720.30
7.0.40.0170.05320.09
7.0.30.0100.08020.15
7.0.20.0100.08320.04
7.0.10.0130.07720.14
7.0.00.0130.04320.10
5.6.280.0070.07021.13
5.6.250.0000.08320.82
5.6.240.0030.05320.57
5.6.230.0100.07020.63
5.6.220.0070.08020.64
5.6.210.0000.05720.75
5.6.200.0030.08020.94
5.6.190.0130.03321.11
5.6.180.0100.08321.08
5.6.170.0000.09021.14
5.6.160.0070.08721.01
5.6.150.0170.05321.03
5.6.140.0070.08321.10
5.6.130.0130.03320.98
5.6.120.0100.06321.04
5.6.110.0070.07721.12
5.6.100.0100.08021.16
5.6.90.0130.08021.02
5.6.80.0070.04720.32
5.6.70.0000.05020.51
5.6.60.0000.04320.32
5.6.50.0000.04320.52
5.6.40.0130.03320.46
5.6.30.0030.04020.32
5.6.20.0170.02320.29
5.6.10.0030.04020.37
5.6.00.0000.04320.41
5.5.380.0100.07720.52
5.5.370.0130.07320.45
5.5.360.0030.06020.34
5.5.350.0130.07320.43
5.5.340.0170.07020.61
5.5.330.0000.05320.92
5.5.320.0070.08020.73
5.5.310.0070.08320.82
5.5.300.0070.05020.93
5.5.290.0130.06720.91
5.5.280.0030.09020.88
5.5.270.0100.07320.88
5.5.260.0070.08020.63
5.5.250.0200.05320.63
5.5.240.0030.05320.22
5.5.230.0070.05320.01
5.5.220.0000.04320.29
5.5.210.0070.03720.11
5.5.200.0070.03720.19
5.5.190.0030.04020.12
5.5.180.0030.04720.21
5.5.160.0070.03720.21
5.5.150.0030.06320.08
5.5.140.0100.03320.24
5.5.130.0170.06720.09
5.5.120.0000.04320.23
5.5.110.0030.04020.16
5.5.100.0070.04020.16
5.5.90.0030.06320.01
5.5.80.0030.05019.96
5.5.70.0070.04320.08
5.5.60.0100.04320.14
5.5.50.0030.04320.05
5.5.40.0070.04020.14
5.5.30.0030.04320.02
5.5.20.0030.04020.08
5.5.10.0130.03320.06
5.5.00.0100.05720.06
5.4.450.0000.04719.38
5.4.440.0100.06019.36
5.4.430.0100.04719.27
5.4.420.0100.07319.30
5.4.410.0070.06319.23
5.4.400.0030.03718.93
5.4.390.0000.04319.10
5.4.380.0030.03719.08
5.4.370.0070.03319.06
5.4.360.0000.04018.97
5.4.350.0100.02719.08
5.4.340.0070.04319.12
5.4.320.0070.04018.98
5.4.310.0030.06719.03
5.4.300.0070.03318.96
5.4.290.0100.05019.02
5.4.280.0030.05018.95
5.4.270.0130.03019.13
5.4.260.0000.05319.05
5.4.250.0070.03019.13
5.4.240.0100.07318.81
5.4.230.0030.03719.23
5.4.220.0030.04018.90
5.4.210.0100.03019.13
5.4.200.0000.03719.05
5.4.190.0030.03718.97
5.4.180.0100.05718.81
5.4.170.0070.03719.09
5.4.160.0000.04018.88
5.4.150.0070.03318.77
5.4.140.0030.04716.43
5.4.130.0100.02716.36
5.4.120.0030.03316.28
5.4.110.0030.03716.21
5.4.100.0100.04016.41
5.4.90.0030.03716.43
5.4.80.0000.04016.38
5.4.70.0100.05016.41
5.4.60.0000.04016.21
5.4.50.0030.06716.38
5.4.40.0100.04016.45
5.4.30.0070.06716.18
5.4.20.0100.05316.36
5.4.10.0100.06716.33
5.4.00.0030.04315.75
5.3.290.0100.03314.52
5.3.280.0100.03014.56
5.3.270.0030.03714.56
5.3.260.0000.04014.57
5.3.250.0030.03714.60
5.3.240.0030.04714.46
5.3.230.0000.04014.59
5.3.220.0000.03714.43
5.3.210.0070.03314.43
5.3.200.0100.03014.44
5.3.190.0070.04314.52
5.3.180.0030.03714.57
5.3.170.0000.04014.57
5.3.160.0030.03314.50
5.3.150.0100.03014.55
5.3.140.0100.04014.51
5.3.130.0100.06714.52
5.3.120.0170.06714.57
5.3.110.0100.07714.49
5.3.100.0030.08013.89
5.3.90.0100.06714.00
5.3.80.0030.06714.01
5.3.70.0100.06713.96
5.3.60.0030.07714.00
5.3.50.0030.07013.71
5.3.40.0130.06713.90
5.3.30.0100.07013.86
5.3.20.0000.07013.56
5.3.10.0100.04713.67
5.3.00.0130.06313.61
5.2.170.0100.05711.10
5.2.160.0000.03711.16
5.2.150.0100.06011.00
5.2.140.0070.06011.00
5.2.130.0030.06011.13
5.2.120.0170.05310.95
5.2.110.0100.05710.96
5.2.100.0100.04311.02
5.2.90.0070.05311.13
5.2.80.0100.05711.12
5.2.70.0070.06710.92
5.2.60.0070.04711.05
5.2.50.0000.04311.02
5.2.40.0070.06010.98
5.2.30.0070.03310.77
5.2.20.0100.05710.91
5.2.10.0030.04310.89
5.2.00.0030.03710.64
5.1.60.0030.04710.00
5.1.50.0100.04310.05
5.1.40.0000.03310.05
5.1.30.0070.05710.29
5.1.20.0030.05310.41
5.1.10.0030.05010.10
5.1.00.0100.0509.92
5.0.50.0030.0438.65
5.0.40.0030.0338.65
5.0.30.0000.0708.65
5.0.20.0100.0338.65
5.0.10.0030.0438.65
5.0.00.0030.0278.65
4.4.90.0030.0338.65
4.4.80.0030.0338.65
4.4.70.0000.0338.65
4.4.60.0030.0308.65
4.4.50.0070.0278.65
4.4.40.0000.0578.65
4.4.30.0030.0338.65
4.4.20.0000.0238.65
4.4.10.0000.0208.65
4.4.00.0000.0308.65
4.3.110.0000.0208.65
4.3.100.0030.0378.65
4.3.90.0070.0278.65
4.3.80.0030.0478.65
4.3.70.0070.0238.65
4.3.60.0030.0338.65
4.3.50.0000.0278.65
4.3.40.0000.0308.65
4.3.30.0000.0208.65
4.3.20.0000.0278.65
4.3.10.0030.0138.65
4.3.00.0000.0238.65

preferences:
42.09 ms | 401 KiB | 5 Q