3v4l.org

run code in 300+ PHP versions simultaneously
<?php $two_dimention = [ ["id" => 4, "name" => "Home", "parent" => 0, "depth" => 0], ["id" => 5, "name" => "Menu 1", "parent" => 0, "depth" => 0], ["id" => 6, "name" => "Menu 2", "parent" => 0, "depth" => 0], ["id" => 8, "name" => "Menu 2.1", "parent" => 6, "depth" => 1], ["id" => 10, "name" => "Menu 2.1.1", "parent" => 8, "depth" => 2], ["id" => 11, "name" => "Menu 2.1.2", "parent" => 8, "depth" => 2], ["id" => 9, "name" => "Menu 2.2", "parent" => 6, "depth" => 1], ["id" => 7, "name" => "Menu 3", "parent" => 0, "depth" => 0], ["id" => 18, "name" => "Menu 3.1", "parent" => 7, "depth" => 1], ]; function makeRecursive($d, $r = 0, $pk = 'parent', $k = 'id', $c = 'children') { $m = []; foreach ($d as $e) { isset($m[$e[$pk]]) ?: $m[$e[$pk]] = []; isset($m[$e[$k]]) ?: $m[$e[$k]] = []; $m[$e[$pk]][] = array_merge($e, [$c => &$m[$e[$k]]]); } return $m[$r]; // remove [0] if there could be more than one root nodes } function nested2ul($data) { $result = []; if (sizeof($data) > 0) { $result[] = '<ul>'; foreach ($data as $entry) { $result[] = sprintf( '<li>%s %s</li>', $entry['name'], nested2ul($entry['children']) ); } $result[] = '</ul>'; } return implode($result); } $temp= makeRecursive($two_dimention); echo nested2ul($temp);

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.0070.01518.32
8.3.50.0140.00016.30
8.3.40.0110.01118.83
8.3.30.0110.00718.79
8.3.20.0030.00520.64
8.3.10.0000.00820.30
8.3.00.0030.00622.55
8.2.180.0160.00018.41
8.2.170.0090.00622.96
8.2.160.0100.00622.27
8.2.150.0000.01124.18
8.2.140.0000.00824.66
8.2.130.0000.00726.16
8.2.120.0050.00319.86
8.2.110.0050.00520.54
8.2.100.0030.00917.91
8.2.90.0040.00419.21
8.2.80.0050.00317.97
8.2.70.0030.00617.63
8.2.60.0000.00818.05
8.2.50.0090.00018.16
8.2.40.0000.00819.77
8.2.30.0020.00517.73
8.2.20.0060.00318.14
8.2.10.0040.00419.40
8.2.00.0040.00419.21
8.1.280.0070.00725.92
8.1.270.0000.00922.00
8.1.260.0070.00326.35
8.1.250.0000.00728.09
8.1.240.0000.01022.29
8.1.230.0110.00020.97
8.1.220.0040.00418.77
8.1.210.0040.00418.86
8.1.200.0090.00017.48
8.1.190.0050.00317.23
8.1.180.0030.00519.01
8.1.170.0040.00420.50
8.1.160.0040.00419.08
8.1.150.0070.00018.94
8.1.140.0000.00720.82
8.1.130.0070.00020.16
8.1.120.0040.00417.55
8.1.110.0080.00017.50
8.1.100.0000.00717.37
8.1.90.0030.00317.37
8.1.80.0080.00017.35
8.1.70.0040.00417.47
8.1.60.0000.00817.62
8.1.50.0000.00817.50
8.1.40.0000.00817.43
8.1.30.0040.00417.61
8.1.20.0000.00817.71
8.1.10.0050.00317.63
8.1.00.0040.00417.52
8.0.300.0040.00419.97
8.0.290.0040.00417.16
8.0.280.0040.00418.65
8.0.270.0070.00017.95
8.0.260.0000.00620.14
8.0.250.0050.00316.91
8.0.240.0070.00016.94
8.0.230.0030.00317.04
8.0.220.0080.00016.89
8.0.210.0050.00216.81
8.0.200.0060.00316.98
8.0.190.0040.00417.02
8.0.180.0000.00816.84
8.0.170.0060.00316.82
8.0.160.0000.00817.01
8.0.150.0070.00016.93
8.0.140.0030.00516.93
8.0.130.0030.00313.42
8.0.120.0000.00816.77
8.0.110.0030.00516.84
8.0.100.0000.00716.87
8.0.90.0000.00816.82
8.0.80.0070.01416.89
8.0.70.0040.00416.83
8.0.60.0050.00216.80
8.0.50.0070.00016.89
8.0.30.0080.01417.19
8.0.20.0120.00617.24
8.0.10.0000.00817.10
8.0.00.0050.01716.89
7.4.330.0000.00516.82
7.4.320.0030.00316.48
7.4.300.0030.00316.59
7.4.290.0080.00016.43
7.4.280.0000.00816.53
7.4.270.0040.00416.54
7.4.260.0060.00013.20
7.4.250.0040.00416.66
7.4.240.0030.00316.63
7.4.230.0070.00016.64
7.4.220.0020.00516.56
7.4.210.0050.00916.56
7.4.200.0070.00016.36
7.4.140.0110.01217.86
7.4.130.0070.01016.39
7.4.120.0070.01016.50
7.4.110.0100.01016.42
7.4.100.0110.00616.72
7.4.90.0100.01016.44
7.4.80.0060.01019.39
7.4.70.0030.01316.60
7.4.60.0120.00416.53
7.4.50.0070.01116.48
7.4.40.0090.00916.30
7.4.00.0090.00614.99
7.3.330.0030.00616.44
7.3.320.0000.00713.33
7.3.310.0000.00716.25
7.3.300.0030.00316.32
7.3.290.0030.00316.25
7.3.260.0070.01116.49
7.3.240.0080.00916.58
7.3.230.0090.00916.57
7.3.210.0100.01016.47
7.3.200.0120.00616.60
7.3.190.0130.00316.54
7.3.180.0110.01116.43
7.3.170.0070.01016.46
7.3.160.0120.00816.37
7.3.120.0070.01015.16
7.3.110.0040.01115.05
7.3.100.0000.01414.90
7.3.90.0050.01014.90
7.3.80.0060.01014.75
7.3.70.0080.01014.89
7.3.60.0090.00714.84
7.3.50.0080.00714.82
7.3.40.0110.00514.51
7.3.30.0060.01114.83
7.3.20.0060.00916.55
7.3.10.0060.01016.63
7.3.00.0010.01616.70
7.2.330.0030.02016.77
7.2.320.0000.01816.74
7.2.310.0060.01016.79
7.2.300.0100.00616.72
7.2.290.0060.01016.71
7.2.240.0030.01015.33
7.2.230.0030.01315.39
7.2.220.0090.00515.18
7.2.210.0080.00415.20
7.2.200.0070.01015.09
7.2.190.0080.01114.97
7.2.180.0050.01115.20
7.2.170.0080.00815.13
7.2.160.0050.01014.94
7.2.150.0020.01316.99
7.2.140.0080.00917.02
7.2.130.0070.00916.82
7.2.120.0080.00816.86
7.2.110.0060.01116.88
7.2.100.0080.00916.92
7.2.90.0090.00716.89
7.2.80.0080.00916.77
7.2.70.0080.01116.98
7.2.60.0050.01317.03
7.2.50.0090.00916.98
7.2.40.0050.01016.87
7.2.30.0090.00716.91
7.2.20.0070.01016.87
7.2.10.0070.01016.98
7.2.00.0060.01016.95
7.1.330.0040.00716.03
7.1.320.0100.00515.93
7.1.310.0080.00815.86
7.1.300.0080.00615.82
7.1.290.0070.00915.85
7.1.280.0080.00915.83
7.1.270.0060.01015.76
7.1.260.0080.00615.79
7.1.250.0120.00315.78

preferences:
60.46 ms | 400 KiB | 5 Q