3v4l.org

run code in 300+ PHP versions simultaneously
<?php function &buildTreeHelper(&$array, $currentLevel = 1) { $result = array(); $lastIndex = 0; while($pair = each($array)) { list(, $row) = $pair; $level = $row['level']; if ($level > $currentLevel) { $result[$lastIndex]['children'] = &buildTreeHelper($array, $level); } else if ($level == $currentLevel) { $result[++$lastIndex] = $row; } else { prev($array); // shift back break; } } return $result; } function buildTree($array) { reset($array); return buildTreeHelper($array); } $array = [ ['level'=>1, 'name' => 'Root #1'], ['level'=>1, 'name' => 'Root #2'], ['level'=>2, 'name' => 'subroot 2-1'], ['level'=>3, 'name' => '__subroot 2-1/1'], ['level'=>3, 'name' => '__subroot 2-1/2'], ['level'=>4, 'name' => '__subroot 2-2/1'], ['level'=>2, 'name' => 'subroot 2-2'], ['level'=>2, 'name' => 'subroot 2-3'], ['level'=>1, 'name' => 'Root #3'] ]; $time = microtime(true); print_r(buildTree($array)); echo round(microtime(true) - $time, 10);

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)
7.4.10.0060.01314.89
7.4.00.0070.01314.84
7.3.130.0070.01415.13
7.3.120.0130.00714.95
7.3.110.0060.01315.02
7.3.100.0060.00915.03
7.3.90.0090.00314.82
7.3.80.0110.00014.99
7.3.70.0000.01414.95
7.3.60.0030.01015.06
7.3.50.0090.00014.92
7.3.40.0040.00714.87
7.3.30.0030.01014.64
7.3.20.0040.01116.51
7.3.10.0090.00616.60
7.3.00.0100.00316.89
7.2.260.0150.00614.91
7.2.250.0070.01314.84
7.2.240.0060.00915.20
7.2.230.0060.00914.97
7.2.220.0060.00914.86
7.2.210.0080.00814.96
7.2.200.0100.00714.78
7.2.190.0080.00815.21
7.2.180.0070.00714.98
7.2.170.0090.00614.98
7.2.160.0030.00615.19
7.2.150.0060.01017.06
7.2.140.0100.00317.05
7.2.130.0090.00616.97
7.2.120.0000.01417.05
7.2.110.0080.00416.95
7.2.100.0030.01316.99
7.2.90.0070.01016.97
7.2.80.0000.01516.70
7.2.70.0100.00617.09
7.2.60.0120.00317.04
7.2.50.0080.00817.10
7.2.40.0070.01016.96
7.2.30.0060.00616.99
7.2.20.0090.00616.81
7.2.10.0120.00616.94
7.2.00.0020.01218.05
7.1.330.0070.00715.84
7.1.320.0000.01315.55
7.1.310.0000.01515.70
7.1.300.0070.00715.98
7.1.290.0030.01015.79
7.1.280.0070.00415.97
7.1.270.0060.00915.86
7.1.260.0030.00915.48
7.1.250.0070.00715.88
7.1.240.0070.00715.94
7.1.230.0030.00615.66
7.1.220.0000.01015.69
7.1.210.0040.00815.86
7.1.200.0070.01015.88
7.1.190.0090.00615.93
7.1.180.0060.00915.47
7.1.170.0060.00615.73
7.1.160.0040.00415.76
7.1.150.0150.00015.97
7.1.140.0060.00815.73
7.1.130.0030.01415.91
7.1.120.0000.01415.55
7.1.110.0040.01115.83
7.1.100.0070.00315.96
7.1.90.0000.01116.04
7.1.80.0030.01415.88
7.1.70.0070.00216.55
7.1.60.0120.00617.46
7.1.50.0080.01216.28
7.1.40.0060.00815.71
7.1.30.0030.01015.83
7.1.20.0000.01215.75
7.1.10.0030.01015.52
7.1.00.0020.03519.22
7.0.330.0030.01315.41
7.0.320.0030.00715.50
7.0.310.0100.00615.57
7.0.300.0040.01115.21
7.0.290.0000.01515.49
7.0.280.0000.01715.41
7.0.270.0000.01315.45
7.0.260.0070.01115.20
7.0.250.0030.01415.54
7.0.240.0100.00315.35
7.0.230.0060.00915.25
7.0.220.0040.01215.36
7.0.210.0090.00315.54
7.0.200.0070.00415.98
7.0.190.0040.01415.47
7.0.180.0000.00915.28
7.0.170.0030.00715.36
7.0.160.0030.01015.17
7.0.150.0000.00915.11
7.0.140.0040.04418.70
7.0.130.0040.00715.46
7.0.120.0040.01115.55
7.0.110.0110.00415.53
7.0.100.0110.00415.04
7.0.90.0100.01015.32
7.0.80.0320.04617.75
7.0.70.0190.04017.75
7.0.60.0380.04117.73
7.0.50.0270.05017.90
7.0.40.0120.03716.61
7.0.30.0050.04716.58
7.0.20.0100.03316.77
7.0.10.0030.03516.85
7.0.00.0050.03016.64
5.6.400.0060.00914.13
5.6.390.0120.00414.79
5.6.380.0060.00614.57
5.6.370.0030.01314.18
5.6.360.0090.00014.13
5.6.350.0030.01314.37
5.6.340.0030.01614.38
5.6.330.0060.00914.71
5.6.320.0110.00414.48
5.6.310.0000.01614.46
5.6.300.0040.01513.98
5.6.290.0100.00314.29
5.6.280.0100.03717.73
5.6.270.0130.00314.46
5.6.260.0100.00714.55
5.6.250.0070.01014.40
5.6.240.0000.01014.52
5.6.230.0070.05217.66
5.6.220.0030.04117.55
5.6.210.0060.04117.41
5.6.200.0100.04617.58
5.6.190.0020.04617.76
5.6.180.0100.03817.77
5.6.170.0070.04317.80
5.6.160.0100.04817.81
5.6.150.0050.05017.77
5.6.140.0160.03817.81
5.6.130.0070.04717.78
5.6.120.0050.03317.63
5.6.110.0030.04717.82
5.6.100.0020.03317.62
5.6.90.0020.03217.85
5.6.80.0050.04317.27
5.6.70.0060.04517.48
5.6.60.0090.04317.33
5.6.50.0050.04217.32
5.6.40.0090.04417.36
5.6.30.0110.04317.46
5.6.20.0050.04517.38
5.6.10.0080.04417.37
5.6.00.0080.04517.30
5.5.380.0040.00714.40
5.5.370.0080.04617.24
5.5.360.0030.05417.54
5.5.350.0140.03717.34
5.5.340.0070.04317.70
5.5.330.0090.03817.77
5.5.320.0130.03817.51
5.5.310.0080.04717.69
5.5.300.0080.04717.79
5.5.290.0030.04617.44
5.5.280.0100.04517.77
5.5.270.0070.04917.51
5.5.260.0100.04217.65
5.5.250.0120.03917.53
5.5.240.0090.04017.13
5.5.230.0020.05017.38
5.5.220.0160.03517.30
5.5.210.0090.04517.47
5.5.200.0050.03817.28
5.5.190.0090.03217.36
5.5.180.0120.03717.32
5.5.170.0100.00314.66
5.5.160.0080.03717.30
5.5.150.0110.03317.13
5.5.140.0160.03317.16
5.5.130.0080.04317.40
5.5.120.0090.03517.39
5.5.110.0080.02617.32
5.5.100.0090.02717.28
5.5.90.0080.02717.25
5.5.80.0120.03717.18
5.5.70.0070.04217.10
5.5.60.0070.04217.29
5.5.50.0100.04317.39
5.5.40.0050.03417.33
5.5.30.0100.04017.15
5.5.20.0050.03617.21
5.5.10.0120.03217.13
5.5.00.0070.03417.05
5.4.450.0070.04015.52
5.4.440.0050.02815.61
5.4.430.0040.02915.56
5.4.420.0030.04315.53
5.4.410.0100.04015.52
5.4.400.0010.04415.54
5.4.390.0050.04615.36
5.4.380.0030.04715.48
5.4.370.0030.02815.50
5.4.360.0070.04115.45
5.4.350.0070.03215.40
5.4.340.0060.02515.54
5.4.330.0110.00311.78
5.4.320.0080.03815.44
5.4.310.0110.03815.41
5.4.300.0070.04015.44
5.4.290.0080.03215.37
5.4.280.0030.03915.37
5.4.270.0110.03615.39
5.4.260.0080.04015.36
5.4.250.0080.02215.43
5.4.240.0070.04015.43
5.4.230.0050.02415.37
5.4.220.0120.03715.36
5.4.210.0030.04115.43
5.4.200.0100.03715.44
5.4.190.0030.04415.45
5.4.180.0030.04515.48
5.4.170.0020.04515.49
5.4.160.0070.04615.51
5.4.150.0050.03615.43
5.4.140.0100.03714.18
5.4.130.0070.04114.15
5.4.120.0100.03714.10
5.4.110.0060.02014.12
5.4.100.0040.02014.17
5.4.90.0030.02314.08
5.4.80.0050.02114.12
5.4.70.0060.02014.17
5.4.60.0050.02214.16
5.4.50.0100.01614.13
5.4.40.0070.01814.17
5.4.30.0030.02514.07
5.4.20.0030.02214.08
5.4.10.0070.01814.10
5.4.00.0030.02313.74
5.3.290.0080.04113.26
5.3.280.0050.03513.19
5.3.270.0050.04013.25
5.3.260.0070.04313.17
5.3.250.0020.03813.24
5.3.240.0050.03913.21
5.3.230.0070.02213.23
5.3.220.0070.01913.24
5.3.210.0050.02313.15
5.3.200.0030.02213.19
5.3.190.0100.01813.21
5.3.180.0030.02113.20
5.3.170.0060.02013.20
5.3.160.0060.01913.18
5.3.150.0050.01913.19
5.3.140.0000.02213.17
5.3.130.0030.02213.15
5.3.120.0040.01713.19
5.3.110.0050.01813.13
5.3.100.0050.02012.90
5.3.90.0060.01912.96
5.3.80.0090.01712.92
5.3.70.0050.01812.92
5.3.60.0070.01812.94
5.3.50.0060.01912.91
5.3.40.0020.02412.93
5.3.30.0020.02212.88
5.3.20.0030.01812.76
5.3.10.0020.02112.78
5.3.00.0030.02112.74
5.2.170.0030.02711.72
5.2.160.0030.02711.72
5.2.150.0000.02711.72
5.2.140.0030.02711.72
5.2.130.0030.02311.72
5.2.120.0030.02711.72
5.2.110.0030.02711.72
5.2.100.0070.02311.72
5.2.90.0000.02711.72
5.2.80.0030.02711.72
5.2.70.0030.02311.72
5.2.60.0070.02311.72
5.2.50.0030.02311.72
5.2.40.0100.02311.72
5.2.30.0070.02011.72
5.2.20.0000.03311.72
5.2.10.0070.02011.72
5.2.00.0070.02311.72
5.1.60.0000.02311.72
5.1.50.0000.02311.72
5.1.40.0030.01711.72
5.1.30.0000.02311.72
5.1.20.0000.02711.72
5.1.10.0000.02711.72
5.1.00.0000.03011.72
5.0.50.0000.01711.72
5.0.40.0030.01711.72
5.0.30.0030.02311.72
5.0.20.0000.01711.72
5.0.10.0000.01711.72
5.0.00.0070.02011.72
4.4.90.0000.01311.72
4.4.80.0000.01311.72
4.4.70.0030.01011.72
4.4.60.0000.01311.72
4.4.50.0000.01311.72
4.4.40.0030.02311.72
4.4.30.0000.01311.72
4.4.20.0000.01711.72
4.4.10.0000.01311.72
4.4.00.0030.02311.72
4.3.110.0000.01311.72
4.3.100.0070.00711.72
4.3.90.0030.01011.72
4.3.80.0030.02011.72
4.3.70.0030.01011.72
4.3.60.0000.02011.72
4.3.50.0000.01311.72
4.3.40.0070.01711.72
4.3.30.0030.01011.72
4.3.20.0030.01311.72
4.3.10.0000.01711.72
4.3.00.0030.01311.72

preferences:
43.05 ms | 401 KiB | 5 Q