3v4l.org

run code in 300+ PHP versions simultaneously
<?php $comments = [ 1 => ['content' => "The first comment", 'parent' => 0], 2 => ['content' => "The second comment", 'parent' => 0], 3 => ['content' => "Reply of first comment", 'parent' => 1], 4 => ['content' => "Another reply of first comemnt", 'parent' => 1], 5 => ['content' => "Reply of a reply of the first comment", 'parent' => 4] ]; foreach($comments as $id => &$value) { # check if there is a parent if ($parentId = $value['parent']) { $comments[$parentId][0][$id] =& $value; # add child to parent unset($comments[$id]); # remove reference from topmost level } } unset($value); # remove iterator reference print_r($comments); # your tree // foreach($comments as $id => &$c) { // if (isset($comments[$c['parent']])) { // $comments[$c['parent']]['comments'][$id] =& $c; // unset($comments[$id]); // } // } // var_dump($comments);

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.0180.00316.88
8.3.50.0160.00616.71
8.3.40.0040.01118.79
8.3.30.0000.01418.79
8.3.20.0040.01120.16
8.3.10.0000.00721.85
8.3.00.0040.00419.44
8.2.180.0000.01418.29
8.2.170.0070.01022.96
8.2.160.0070.00720.45
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0030.00626.16
8.2.120.0060.00317.75
8.2.110.0100.00022.29
8.2.100.0070.00417.85
8.2.90.0040.00417.97
8.2.80.0040.00417.97
8.2.70.0000.00917.75
8.2.60.0040.00417.93
8.2.50.0090.00318.07
8.2.40.0000.00921.06
8.2.30.0040.00418.19
8.2.20.0000.00717.72
8.2.10.0000.00818.23
8.2.00.0070.00018.11
8.1.280.0110.00325.92
8.1.270.0070.00720.36
8.1.260.0060.00326.35
8.1.250.0030.00528.09
8.1.240.0090.00023.96
8.1.230.0000.01119.17
8.1.220.0080.00017.74
8.1.210.0030.00618.77
8.1.200.0090.00017.23
8.1.190.0030.00617.35
8.1.180.0040.00418.10
8.1.170.0000.00818.65
8.1.160.0000.00821.93
8.1.150.0000.00718.95
8.1.140.0040.00517.37
8.1.130.0000.00717.71
8.1.120.0000.00717.45
8.1.110.0030.00517.54
8.1.100.0000.00817.47
8.1.90.0040.00417.44
8.1.80.0050.00217.45
8.1.70.0000.00817.42
8.1.60.0090.00017.59
8.1.50.0030.00517.57
8.1.40.0030.00617.45
8.1.30.0000.00817.56
8.1.20.0080.00017.71
8.1.10.0070.00017.47
8.1.00.0050.00217.40
8.0.300.0040.00420.16
8.0.290.0040.00416.88
8.0.280.0030.00318.52
8.0.270.0070.00017.23
8.0.260.0040.00417.23
8.0.250.0040.00416.93
8.0.240.0110.00017.02
8.0.230.0040.00416.91
8.0.220.0030.00316.96
8.0.210.0020.00516.84
8.0.200.0000.00716.89
8.0.190.0050.00317.05
8.0.180.0090.00016.87
8.0.170.0080.00016.83
8.0.160.0000.00716.80
8.0.150.0000.00716.93
8.0.140.0000.00916.92
8.0.130.0000.00613.35
8.0.120.0030.00616.95
8.0.110.0000.00816.95
8.0.100.0040.00416.84
8.0.90.0040.00416.88
8.0.80.0040.01816.89
8.0.70.0050.00316.98
8.0.60.0030.00516.77
8.0.50.0000.00816.91
8.0.30.0120.00717.04
8.0.20.0080.01117.40
8.0.10.0040.00417.05
8.0.00.0130.00816.73
7.4.330.0020.00215.14
7.4.320.0000.00616.42
7.4.300.0060.00016.54
7.4.290.0040.00416.53
7.4.280.0040.00416.43
7.4.270.0070.00016.54
7.4.260.0040.00416.61
7.4.250.0090.00016.45
7.4.240.0060.00216.50
7.4.230.0030.00316.51
7.4.220.0030.01416.56
7.4.210.0040.01016.63
7.4.200.0040.00416.35
7.4.160.0030.01316.45
7.4.150.0030.01517.40
7.4.140.0090.01117.86
7.4.130.0090.00916.57
7.4.120.0120.00616.48
7.4.110.0060.01616.58
7.4.100.0230.00016.55
7.4.90.0060.01216.46
7.4.80.0140.00719.39
7.4.70.0060.01216.25
7.4.60.0060.01016.56
7.4.50.0050.00016.58
7.4.40.0070.01016.61
7.4.30.0060.01216.37
7.4.00.0100.00714.90
7.3.330.0040.00513.21
7.3.320.0000.00513.11
7.3.310.0070.00016.34
7.3.300.0070.00016.38
7.3.290.0030.00316.38
7.3.280.0090.00616.35
7.3.270.0030.01517.40
7.3.260.0110.00616.43
7.3.250.0110.01016.43
7.3.240.0100.00716.39
7.3.230.0090.01616.39
7.3.210.0160.00016.35
7.3.200.0060.01119.39
7.3.190.0060.00916.36
7.3.180.0180.00316.44
7.3.170.0050.00516.36
7.3.160.0100.00616.44
7.3.120.0030.01314.99
7.3.110.0030.01315.08
7.3.100.0120.00315.13
7.3.90.0060.00614.75
7.3.80.0100.00614.88
7.3.70.0000.01514.93
7.3.60.0040.01114.98
7.3.50.0030.01314.82
7.3.40.0110.00414.72
7.3.30.0070.01014.79
7.3.20.0090.00616.52
7.3.10.0070.00716.68
7.3.00.0060.00616.92
7.2.330.0100.00716.58
7.2.320.0140.00816.44
7.2.310.0030.01316.71
7.2.300.0000.01716.83
7.2.290.0110.01116.50
7.2.250.0130.00615.03
7.2.240.0120.00314.86
7.2.230.0100.00315.33
7.2.220.0060.00615.11
7.2.210.0030.01215.30
7.2.200.0030.01014.87
7.2.190.0000.01615.16
7.2.180.0040.01115.28
7.2.170.0040.00714.95
7.2.60.0090.00616.56
7.2.00.0070.00419.51
7.1.330.0120.00315.46
7.1.320.0040.00815.57
7.1.310.0100.00715.59
7.1.300.0030.01015.87
7.1.290.0000.01415.74
7.1.280.0000.01015.52
7.1.270.0030.01315.77
7.1.260.0070.00715.63
7.1.200.0090.00315.96
7.1.100.0110.00718.14
7.1.70.0000.00717.22
7.1.60.0070.01620.03
7.1.50.0130.01017.07
7.1.00.0170.06322.51
7.0.200.0100.00316.93
7.0.60.0130.06019.97
7.0.50.0130.06317.82
7.0.40.0170.05020.30
7.0.30.0400.06320.08
7.0.20.0200.04320.27
7.0.10.0000.08020.16
7.0.00.0030.05720.17
5.6.280.0030.07321.07
5.6.210.0070.03720.49
5.6.200.0100.03318.23
5.6.190.0000.06020.39
5.6.180.3470.04020.50
5.6.170.0430.06720.57
5.6.160.0100.03720.46
5.6.150.0130.07718.14
5.6.140.0100.08018.22
5.6.130.0130.08018.21
5.6.120.0030.05021.11
5.6.110.0100.07720.96
5.6.100.0100.06720.96
5.6.90.0070.08721.11
5.6.80.0070.07320.52
5.6.70.3570.03720.34
5.5.350.0000.04320.50
5.5.340.0070.08318.04
5.5.330.0100.05020.57
5.5.320.0300.04320.51
5.5.310.0270.06320.27
5.5.300.0070.03318.00
5.5.290.0100.04318.09
5.5.280.0100.04320.65
5.5.270.0130.03320.76
5.5.260.0070.08720.67
5.5.250.0100.08720.68
5.5.240.0200.06320.36
5.4.450.0230.07019.34
5.4.440.0030.06719.30
5.4.430.0130.05719.46
5.4.420.0100.06019.54
5.4.410.0200.05319.34
5.4.400.0130.05319.15
5.4.390.0170.05018.84
5.4.380.0100.05319.15
5.4.370.0070.06019.01
5.4.360.0230.05319.29
5.4.350.0200.05719.30
5.4.340.0170.05318.83
5.4.320.0170.05319.23
5.4.310.0230.05718.84
5.4.300.0200.05719.38
5.4.290.0070.05718.84
5.4.280.0070.06019.28
5.4.270.0100.05719.00
5.4.260.0100.05319.25
5.4.250.0100.05319.05
5.4.240.0130.05018.97
5.4.230.0200.04719.21
5.4.220.0100.05719.27
5.4.210.0200.04319.17
5.4.200.0200.04316.75
5.4.190.0170.04718.92
5.4.180.0200.04318.92
5.4.170.0170.05019.09
5.4.160.0130.05319.17
5.4.150.0130.05319.03
5.4.140.0230.04316.45
5.4.130.0170.04716.56
5.4.120.0130.05016.35
5.4.110.0070.05716.39
5.4.100.0130.05016.34
5.4.90.0030.06016.38
5.4.80.0100.05316.70
5.4.70.0070.05716.38
5.4.60.0230.03716.29
5.4.50.0200.04016.54
5.4.40.0070.06016.40
5.4.30.0170.05316.27
5.4.20.0100.05316.50
5.4.10.0130.04716.29
5.4.00.0070.05315.84

preferences:
84.44 ms | 400 KiB | 5 Q