3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildTree(array $rows, int $parentId = 0): array { $new = []; foreach ($rows as $row) { if ($row['parent_id'] == $parentId) { $new[$row['id']] = buildTree($rows, $row['id']) ?: ''; } } return $new; } $resultSet = [ ['id' => 1, 'parent_id' => 0], ['id' => 2, 'parent_id' => 1], ['id' => 3, 'parent_id' => 2], ['id' => 4, 'parent_id' => 2], ['id' => 5, 'parent_id' => 3], ['id' => 6, 'parent_id' => 3], ['id' => 7, 'parent_id' => 4], ['id' => 8, 'parent_id' => 4], ['id' => 9, 'parent_id' => 4], ]; var_export( buildTree($resultSet) );

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.4.140.0120.00917.67
8.4.130.0110.00917.66
8.4.120.0120.00820.84
8.4.110.0080.01122.58
8.4.100.0100.00317.35
8.4.90.0120.00918.70
8.4.80.0130.00417.93
8.4.70.0150.00517.77
8.4.60.0150.00620.37
8.4.50.0130.00717.63
8.4.40.0090.00019.46
8.4.30.0130.00620.39
8.4.20.0100.00720.13
8.4.10.0100.00722.28
8.3.270.0130.00716.72
8.3.260.0060.00816.55
8.3.250.0140.00418.93
8.3.240.0120.00716.60
8.3.230.0120.00816.67
8.3.220.0060.00717.16
8.3.210.0080.00716.56
8.3.200.0050.00416.25
8.3.190.0080.00917.50
8.3.180.0110.00616.69
8.3.170.0080.00018.84
8.3.160.0060.01218.18
8.3.150.0060.01320.86
8.3.140.0070.00318.28
8.3.130.0070.00716.40
8.3.120.0040.00420.99
8.3.110.0060.00320.94
8.3.100.0060.00324.06
8.3.90.0060.00326.77
8.3.80.0080.00418.27
8.3.70.0170.00716.58
8.3.60.0080.00818.68
8.3.50.0140.00720.13
8.3.40.0070.00720.38
8.3.30.0070.01418.70
8.3.20.0040.00424.18
8.3.10.0050.00224.66
8.3.00.0040.00426.16
8.2.290.0100.00920.72
8.2.280.0070.00818.54
8.2.270.0120.00618.91
8.2.260.0080.00018.42
8.2.250.0040.00416.71
8.2.240.0050.00519.01
8.2.230.0040.00422.58
8.2.220.0060.00337.54
8.2.210.0050.01026.77
8.2.200.0040.00416.63
8.2.190.0150.00616.88
8.2.180.0150.00625.92
8.2.170.0110.00418.71
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0070.00024.66
8.2.130.0040.00426.16
8.2.120.0070.00026.16
8.2.110.0030.00621.04
8.2.100.0060.00619.54
8.2.90.0050.00317.80
8.2.80.0030.00617.97
8.2.70.0040.00417.75
8.2.60.0060.00317.75
8.2.50.0060.00317.98
8.2.40.0030.00619.72
8.2.30.0040.00418.14
8.2.20.0070.00020.50
8.2.10.0040.00418.14
8.2.00.0080.00019.38
8.1.330.0060.00421.95
8.1.320.0110.00916.09
8.1.310.0140.00418.41
8.1.300.0040.00418.66
8.1.290.0090.00030.84
8.1.280.0130.01025.92
8.1.270.0060.00323.99
8.1.260.0070.00026.35
8.1.250.0000.00728.09
8.1.240.0030.00623.92
8.1.230.0060.00622.61
8.1.220.0060.00317.74
8.1.210.0040.00418.90
8.1.200.0110.00017.23
8.1.190.0000.00817.23
8.1.180.0060.00318.10
8.1.170.0060.00317.62
8.1.160.0000.00718.84
8.1.150.0030.00618.64
8.1.140.0050.00217.50
8.1.130.0000.00817.46
8.1.120.0030.00517.38
8.1.110.0000.00717.38
8.1.100.0000.00717.47
8.1.90.0000.00817.50
8.1.80.0040.00417.43
8.1.70.0100.00717.35
8.1.60.0180.00017.47
8.1.50.0110.00817.49
8.1.40.0180.00017.57
8.1.30.0160.00317.54
8.1.20.0130.00517.68
8.1.10.0120.00617.54
8.1.00.0160.00317.46
8.0.300.0070.00019.60
8.0.290.0030.00516.63
8.0.280.0030.00318.43
8.0.270.0000.00816.76
8.0.260.0070.00016.90
8.0.250.0040.00417.00
8.0.240.0080.00016.99
8.0.230.0000.01016.83
8.0.220.0030.00316.80
8.0.210.0000.00716.80
8.0.200.0120.00516.84
8.0.190.0130.00316.93
8.0.180.0080.00816.89
8.0.170.0170.00016.88
8.0.160.0060.00816.95
8.0.150.0170.00016.67
8.0.140.0150.00016.88
8.0.130.0080.00816.68
8.0.120.0050.01016.88
8.0.110.0050.00916.93
8.0.100.0090.00616.89
8.0.90.0120.00616.81
8.0.80.0150.00316.80
8.0.70.0170.00016.71
8.0.60.0140.00016.76
8.0.50.0150.00316.75
8.0.30.0130.00316.76
8.0.20.0070.00716.85
8.0.10.0000.01416.94
7.4.330.0050.00015.55
7.4.320.0060.00016.52
7.4.300.0180.00016.53
7.4.290.0150.00316.48
7.4.280.0170.00016.46
7.4.270.0110.00616.59
7.4.260.0160.00216.38
7.4.250.0160.00316.61
7.4.240.0080.01116.47
7.4.230.0130.00616.60
7.4.220.0120.00416.39
7.4.210.0070.00316.30
7.4.200.0060.00316.45
7.4.190.0060.00316.40
7.4.180.0050.00516.48
7.4.160.0030.00616.46
7.4.150.0080.00416.42
7.4.140.0100.00016.41
7.4.130.0080.00316.44
7.4.120.0050.00516.52
7.4.110.0050.00516.22
7.4.100.0130.00016.60
7.4.90.0120.00216.23
7.4.80.0040.00916.40
7.4.70.0090.00316.55
7.4.60.0140.00016.41
7.4.50.0120.00216.39
7.4.40.0150.00016.25
7.4.30.0100.00316.45
7.4.20.0100.00316.40
7.4.10.0070.00416.54
7.4.00.0130.00016.42

preferences:
106.85 ms | 403 KiB | 5 Q