3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); $items = [ (object)['id' => 1, 'parentId' => 0, 'name' => "foo"], (object)['id' => 2, 'parentId' => 1, 'name' => "bar"], (object)['id' => 3, 'parentId' => 1, 'name' => "qux"], (object)['id' => 4, 'parentId' => 3, 'name' => "zip"], (object)['id' => 5, 'parentId' => 4, 'name' => "baz"] ]; $itemsById = []; foreach ($items as $item) { $itemsById[$item->id] = $item; } // --- foreach ($itemsById as $id => $item) { $itemsById[$item->parentId]->children[] = $item; } var_dump($itemsById);

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.46
8.3.50.0170.01022.00
8.3.40.0100.01018.97
8.3.30.0090.00618.67
8.3.20.0000.00720.30
8.3.10.0070.00023.61
8.3.00.0000.00719.79
8.2.180.0120.00918.54
8.2.170.0070.01122.96
8.2.160.0070.00720.19
8.2.150.0060.00325.66
8.2.140.0050.00324.66
8.2.130.0040.00419.32
8.2.120.0080.00826.35
8.2.110.0080.00020.38
8.2.100.0090.00317.93
8.2.90.0000.00819.38
8.2.80.0040.00417.97
8.2.70.0040.00417.75
8.2.60.0040.00418.03
8.2.50.0080.00018.07
8.2.40.0040.00422.15
8.2.30.0000.00820.72
8.2.20.0000.00917.80
8.2.10.0080.00018.04
8.2.00.0040.00418.16
8.1.280.0110.00625.92
8.1.270.0090.00020.14
8.1.260.0070.00028.09
8.1.250.0080.00028.09
8.1.240.0040.00422.14
8.1.230.0090.00317.66
8.1.220.0040.00417.79
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0060.00317.13
8.1.180.0000.00718.10
8.1.170.0000.00818.44
8.1.160.0050.00220.71
8.1.150.0050.00318.79
8.1.140.0000.00719.63
8.1.130.0000.00717.66
8.1.120.0070.00017.32
8.1.110.0040.00417.50
8.1.100.0030.00417.42
8.1.90.0000.00817.36
8.1.80.0030.00417.33
8.1.70.0040.00417.32
8.1.60.0000.00817.59
8.1.50.0030.00617.55
8.1.40.0000.00817.53
8.1.30.0080.00017.61
8.1.20.0040.00417.65
8.1.10.0040.00417.57
8.1.00.0040.00417.42
8.0.300.0020.00518.77
8.0.290.0040.00416.75
8.0.280.0070.00018.50
8.0.270.0040.00417.22
8.0.260.0030.00317.12
8.0.250.0040.00317.04
8.0.240.0040.00417.02
8.0.230.0030.00316.92
8.0.220.0070.00017.00
8.0.210.0040.00416.87
8.0.200.0070.00316.93
8.0.190.0000.00717.03
8.0.180.0030.00316.87
8.0.170.0050.00316.94
8.0.160.0070.00316.97
8.0.150.0050.00216.84
8.0.140.0040.00416.92
8.0.130.0030.00313.34
8.0.120.0080.00016.82
8.0.110.0000.00716.96
8.0.100.0040.00416.78
8.0.90.0030.00617.00
8.0.80.0070.01016.94
8.0.70.0040.00416.86
8.0.60.0040.00416.85
8.0.50.0050.00217.01
8.0.30.0130.00617.21
8.0.20.0110.00917.40
8.0.10.0050.00317.02
8.0.00.0110.00616.76
7.4.330.0000.00516.76
7.4.320.0030.00316.48
7.4.300.0000.00716.51
7.4.290.0040.00416.50
7.4.280.0090.00016.59
7.4.270.0070.00016.60
7.4.260.0070.00016.59
7.4.250.0000.00716.46
7.4.240.0040.00416.50
7.4.230.0030.00316.50
7.4.220.0130.00916.41
7.4.210.0100.00716.53
7.4.200.0000.00716.61
7.4.160.0110.00616.50
7.4.150.0140.00817.40
7.4.140.0150.00917.86
7.4.130.0130.01216.52
7.4.120.0120.00816.60
7.4.110.0120.01216.60
7.4.100.0100.01116.36
7.4.90.0100.01716.47
7.4.80.0040.01619.39
7.4.70.0100.01116.46
7.4.60.0150.00616.59
7.4.50.0160.00316.42
7.4.40.0070.01316.41
7.4.30.0070.01116.46
7.4.00.0070.01114.93
7.3.330.0000.00613.20
7.3.320.0030.00313.20
7.3.310.0070.00016.25
7.3.300.0030.00316.35
7.3.290.0030.00516.38
7.3.280.0120.00516.35
7.3.270.0080.01217.40
7.3.260.0100.01016.36
7.3.250.0100.01516.53
7.3.240.0160.00316.42
7.3.230.0100.01016.41
7.3.210.0050.01516.52
7.3.200.0140.00716.55
7.3.190.0120.00916.39
7.3.180.0000.01816.48
7.3.170.0150.00916.45
7.3.160.0000.02016.33
7.2.330.0130.00616.92
7.2.320.0070.01716.46
7.2.310.0100.01416.36
7.2.300.0080.01216.84
7.2.290.0130.00616.64
7.2.60.0070.00716.93
7.2.00.0100.00719.58
7.1.200.0000.01415.76
7.1.100.0000.00918.28
7.1.70.0050.00217.19
7.1.60.0120.00919.44
7.1.50.0130.00916.95
7.1.00.0070.07322.31
7.0.200.0000.00716.76
7.0.60.0100.06319.88
7.0.50.0130.05317.77
7.0.40.0100.03720.20
7.0.30.0370.07320.33
7.0.20.0370.05720.17
7.0.10.0100.09020.18
7.0.00.0030.06020.18
5.6.280.0070.06320.87
5.6.210.0030.04020.77
5.6.200.0070.04018.09
5.6.190.0100.08020.39
5.6.180.0230.07320.33
5.6.170.0330.07020.54
5.6.160.0130.06320.52
5.6.150.0030.08018.09
5.6.140.0100.07718.12
5.6.130.0030.08318.11
5.6.120.0030.04021.02
5.6.110.0030.04020.99
5.6.100.0100.07020.99
5.6.90.0030.07020.96
5.6.80.0130.07720.38
5.5.350.0200.07720.41
5.5.340.0000.09018.03
5.5.330.0030.04020.13
5.5.320.0500.04320.34
5.5.310.0270.05720.32
5.5.300.0130.04017.95
5.5.290.0030.04018.02
5.5.280.0100.07720.80
5.5.270.0130.05020.89
5.5.260.0030.05720.87
5.5.250.0130.06720.61
5.5.240.0170.07020.26

preferences:
94.79 ms | 401 KiB | 5 Q