3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'id' => 1, 'title' => 'dir 1', 'parent_id' => 0, ], [ 'id' => 2, 'title' => 'dir 2', 'parent_id' => 0, ], [ 'id' => 3, 'title' => 'dir 3', 'parent_id' => 2, ], [ 'id' => 4, 'title' => 'dir 4', 'parent_id' => 3, ], [ 'id' => 5, 'title' => 'dir 5', 'parent_id' => 6, ], [ 'id' => 6, 'title' => 'dir 6', 'parent_id' => 0, ], ]; function build_tree($array, $parent_id = 0) { $result = []; foreach ($array as $item) { if ($item['parent_id'] == $parent_id) { $new_item = $item; $new_item['children'] = build_tree($array, $new_item['id']); $result[] = $new_item; } } return $result; } $tree = build_tree($array); print_r($tree);

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.0130.01018.18
8.3.50.0100.00316.37
8.3.40.0070.00718.71
8.3.30.0070.00718.85
8.3.20.0050.00220.33
8.3.10.0080.00023.50
8.3.00.0040.00419.69
8.2.180.0120.00918.54
8.2.170.0170.00322.96
8.2.160.0100.00318.80
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00721.00
8.2.120.0070.00026.35
8.2.110.0060.00321.09
8.2.100.0070.00718.03
8.2.90.0040.00419.41
8.2.80.0060.00318.05
8.2.70.0050.00317.50
8.2.60.0060.00317.93
8.2.50.0030.00618.10
8.2.40.0030.00520.45
8.2.30.0040.00419.34
8.2.20.0040.00418.14
8.2.10.0030.00618.15
8.2.00.0040.00418.19
8.1.280.0120.00925.92
8.1.270.0080.00022.07
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0060.00319.13
8.1.230.0000.01122.20
8.1.220.0000.00817.74
8.1.210.0050.00318.77
8.1.200.0040.00417.23
8.1.190.0040.00417.23
8.1.180.0080.00018.10
8.1.170.0040.00418.37
8.1.160.0040.00418.95
8.1.150.0000.01018.96
8.1.140.0000.00719.51
8.1.130.0050.00318.78
8.1.120.0040.00417.52
8.1.110.0000.00717.46
8.1.100.0060.00317.34
8.1.90.0040.00417.47
8.1.80.0070.00017.49
8.1.70.0030.00317.51
8.1.60.0030.00517.66
8.1.50.0040.00417.51
8.1.40.0000.00817.55
8.1.30.0000.00717.68
8.1.20.0040.00417.70
8.1.10.0000.00817.56
8.1.00.0000.00817.45
8.0.300.0040.00418.77
8.0.290.0040.00416.75
8.0.280.0070.00018.34
8.0.270.0000.00717.28
8.0.260.0080.00016.89
8.0.250.0000.00716.84
8.0.240.0050.00216.86
8.0.230.0000.00716.98
8.0.220.0000.00716.80
8.0.210.0030.00516.87
8.0.200.0030.00316.97
8.0.190.0080.00016.93
8.0.180.0040.00416.84
8.0.170.0000.00716.93
8.0.160.0040.00416.96
8.0.150.0030.00316.89
8.0.140.0000.00716.88
8.0.130.0000.00513.34
8.0.120.0070.00016.83
8.0.110.0040.00416.86
8.0.100.0040.00416.97
8.0.90.0000.00716.84
8.0.80.0160.00616.87
8.0.70.0080.00016.82
8.0.60.0040.00416.79
8.0.50.0000.00716.88
8.0.30.0090.01017.10
8.0.20.0140.00417.40
8.0.10.0030.00516.81
8.0.00.0030.01416.62
7.4.330.0000.00615.55
7.4.320.0030.00316.47
7.4.300.0030.00316.64
7.4.290.0000.00716.55
7.4.280.0080.00316.49
7.4.270.0050.00216.53
7.4.260.0040.00416.64
7.4.250.0030.00316.59
7.4.240.0000.00716.54
7.4.230.0000.00716.43
7.4.220.0100.01016.67
7.4.210.0070.00716.64
7.4.200.0040.00416.70
7.4.160.0080.00816.48
7.4.150.0030.02017.40
7.4.140.0120.01017.86
7.4.130.0130.00816.49
7.4.120.0100.00816.54
7.4.110.0030.01416.66
7.4.100.0130.00916.67
7.4.90.0070.01016.45
7.4.80.0090.01219.39
7.4.70.0090.00716.45
7.4.60.0030.01416.43
7.4.50.0030.01016.55
7.4.40.0060.01216.48
7.4.30.0050.01116.47
7.4.10.0070.01014.90
7.4.00.0080.00814.99
7.3.330.0050.00013.38
7.3.320.0000.00513.20
7.3.310.0000.00716.38
7.3.300.0070.00016.24
7.3.290.0080.00716.38
7.3.280.0060.01016.36
7.3.270.0030.01417.40
7.3.260.0090.00716.26
7.3.250.0120.00716.48
7.3.240.0080.01116.62
7.3.230.0130.00316.30
7.3.210.0220.02216.33
7.3.200.0100.01016.67
7.3.190.0030.01316.66
7.3.180.0000.01616.30
7.3.170.0090.00616.53
7.3.160.0080.00916.53
7.3.130.0100.00614.55
7.3.120.0100.01015.04
7.3.110.0150.00314.84
7.3.100.0100.00614.77
7.3.90.0090.01014.57
7.3.80.0030.00915.05
7.3.70.0120.00414.96
7.3.60.0060.00614.57
7.3.50.0060.00614.95
7.3.40.0100.00014.85
7.3.30.0070.00314.50
7.3.20.0100.00016.42
7.3.10.0030.00916.38
7.3.00.0070.00716.66
7.2.330.0120.00616.52
7.2.320.0110.00716.67
7.2.310.0070.01016.38
7.2.300.0140.00316.34
7.2.290.0110.01116.79
7.2.260.0060.00915.24
7.2.250.0100.00715.14
7.2.240.0100.00614.96
7.2.230.0100.00715.32
7.2.220.0070.01415.14
7.2.210.0120.00015.11
7.2.200.0070.00714.99
7.2.190.0100.00314.95
7.2.180.0060.01315.10
7.2.170.0000.01214.91
7.2.160.0000.01315.15
7.2.150.0060.00916.84
7.2.140.0090.00616.69
7.2.130.0030.01416.70
7.2.120.0030.01016.93
7.2.110.0000.01316.98
7.2.100.0070.00716.80
7.2.90.0130.00017.03
7.2.80.0030.01016.70
7.2.70.0120.00417.10
7.2.60.0070.00716.97
7.2.50.0060.00616.97
7.2.40.0030.01017.09
7.2.30.0090.00616.79
7.2.20.0120.00016.98
7.2.10.0030.01416.94
7.2.00.0030.01018.07
7.1.330.0040.01115.70
7.1.320.0100.01015.51
7.1.310.0040.01115.80
7.1.300.0070.01115.45
7.1.290.0080.00015.61
7.1.280.0060.00615.82
7.1.270.0060.00315.70
7.1.260.0070.00315.56
7.1.250.0040.01115.80
7.1.240.0000.01115.96
7.1.230.0000.01315.86
7.1.220.0030.01015.75
7.1.210.0070.00715.71
7.1.200.0050.00815.62
7.1.190.0060.00915.73
7.1.180.0100.00015.93
7.1.170.0000.01115.96
7.1.160.0030.00715.67
7.1.150.0060.00915.75
7.1.140.0030.00715.91
7.1.130.0060.00615.58
7.1.120.0000.01115.88
7.1.110.0040.00415.83
7.1.100.0000.01116.90
7.1.90.0000.01115.73
7.1.80.0040.00815.94
7.1.70.0210.01216.38
7.1.60.0380.00724.67
7.1.50.0330.01225.27
7.1.40.0210.01425.16
7.1.30.0230.00824.07
7.1.20.0250.01124.03
7.1.10.0230.00916.33
7.1.00.0210.01115.27
7.0.330.0080.00815.15
7.0.320.0000.01115.43
7.0.310.0000.01515.35
7.0.300.0060.00615.48
7.0.290.0070.01115.30
7.0.280.0030.00915.29
7.0.270.0060.00615.30
7.0.260.0090.00615.41
7.0.250.0070.00715.42
7.0.240.0000.01315.41
7.0.230.0030.01015.39
7.0.220.0060.00615.39
7.0.210.0110.00415.45
7.0.200.0060.01116.21
7.0.190.0250.00815.10
7.0.180.0240.00315.01
7.0.170.0070.00815.98
7.0.160.0130.00715.79
7.0.150.0220.01314.82
7.0.140.0230.01015.03
7.0.130.0160.00715.13
7.0.120.0230.01215.08
7.0.110.0040.01215.82
7.0.100.0040.01115.78
7.0.90.0160.01315.02
7.0.80.0030.01515.78
7.0.70.0230.00314.99
7.0.60.0230.01114.77
7.0.50.0250.00914.90
7.0.40.0230.01014.09
7.0.30.0230.01014.08
7.0.20.0240.00814.88
7.0.10.0250.00914.12
7.0.00.0250.00514.00
5.6.400.0090.00613.98
5.6.390.0130.00714.74
5.6.380.0040.01214.46
5.6.370.0040.00714.55
5.6.360.0130.00314.72
5.6.350.0030.01014.33
5.6.340.0160.00714.15
5.6.330.0030.00614.63
5.6.320.0060.01214.57
5.6.310.0000.01614.66
5.6.300.0160.00314.43
5.6.290.0030.00914.60
5.6.280.0030.01314.34
5.6.270.0100.00614.22
5.6.260.0100.01014.65
5.6.250.0070.00714.14
5.6.240.0070.01414.34
5.6.230.0090.01214.54
5.6.220.0040.01114.64
5.6.210.0060.01014.30
5.6.200.0130.00714.42
5.6.190.0060.00914.45
5.6.180.0090.00914.39
5.6.170.0060.00914.32
5.6.160.0040.01614.32
5.6.150.0110.00714.47
5.6.140.0060.00614.32
5.6.130.0070.01014.27
5.6.120.0100.00714.27
5.6.110.0030.01714.38
5.6.100.0190.00014.40
5.6.90.0120.00613.97
5.6.80.0100.00714.42
5.6.70.0030.01614.10
5.6.60.0040.01114.43
5.6.50.0060.00914.27
5.6.40.0130.00314.16
5.6.30.0140.00314.35
5.6.20.0110.00314.15
5.6.10.0150.00414.27
5.6.00.0120.00414.05

preferences:
53.01 ms | 400 KiB | 5 Q