3v4l.org

run code in 300+ PHP versions simultaneously
<?php $menu = array( array(1,3,'Wurm 1.1', 2, 10), array(2,6,'Vogel 2.1', 2, 30), array(3,0,'Tiger 1', 1, 10), array(4,6,'Hund 2.2', 2, 40), array(5,3,'Katze 1.2', 2, 11), array(6,0,'Pferd 2', 1, 20), array(7,1,'Baer 1.1.1', 3, 0), array(8,3,'Schwein 1.3', 2, 12), array(9,4,'Esel 2.2.1', 3, 0), ); // Algorithmus hier /* steps: 1. sort items by levelId and sortId - finished 2. get max levelId value 'x' = iterations - ...that seems to be not the way to go. better way would be recursion for each element and search for children belonging to the current menuId.... 3. ... */ const IDX_ID = 0; const IDX_PARENT = 1; const IDX_SORT = 4; $result = array(); foreach ($menu as $key => $row){ $levelId[$key] = $row[3]; $sortId[$key] = $row[4]; } array_multisort($levelId, SORT_ASC, $sortId, SORT_ASC, $menu); $parentId = 4; $items = array_filter($menu, function($item) use ($parentId) { return $item[IDX_PARENT] == $parentId; }); var_dump($items); $target = array( array(3,0,'Tiger 1', 1, 10), array(1,3,'Wurm 1.1', 2, 10), array(7,1,'Baer 1.1.1', 3, 0), array(5,3,'Katze 1.2', 2, 11), array(8,3,'Schwein 1.3', 2, 12), array(6,0,'Pferd 2', 1, 20), array(2,6,'Vogel 2.1', 2, 30), array(4,6,'Hund 2.2', 2, 40), array(9,4,'Esel 2.2.1', 3, 0), ); //var_dump($result == $target);

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.50
8.3.50.0070.00719.74
8.3.40.0140.00318.79
8.3.30.0000.01518.89
8.3.20.0050.00318.97
8.3.10.0040.00423.51
8.3.00.0040.00420.89
8.2.180.0090.00616.36
8.2.170.0070.00722.96
8.2.160.0040.01120.50
8.2.150.0070.00725.66
8.2.140.0040.00424.66
8.2.130.0080.00021.00
8.2.120.0020.00526.35
8.2.110.0060.00319.39
8.2.100.0120.00017.59
8.2.90.0060.00318.22
8.2.80.0060.00319.20
8.2.70.0040.00418.16
8.2.60.0000.00817.93
8.2.50.0050.00318.10
8.2.40.0040.00420.61
8.2.30.0030.00619.41
8.2.20.0040.00418.15
8.2.10.0040.00418.12
8.2.00.0030.00517.77
8.1.280.0170.00325.92
8.1.270.0070.00022.19
8.1.260.0090.00028.09
8.1.250.0040.00428.09
8.1.240.0070.00322.53
8.1.230.0080.00420.96
8.1.220.0090.00017.80
8.1.210.0000.01218.98
8.1.200.0060.00317.35
8.1.190.0060.00317.38
8.1.180.0060.00318.10
8.1.170.0020.00518.64
8.1.160.0030.00518.97
8.1.150.0040.00420.23
8.1.140.0070.00019.59
8.1.130.0030.00317.79
8.1.120.0040.00417.53
8.1.110.0000.00817.41
8.1.100.0050.00317.56
8.1.90.0040.00417.39
8.1.80.0040.00417.38
8.1.70.0030.00317.41
8.1.60.0080.00017.55
8.1.50.0050.00317.61
8.1.40.0080.00017.52
8.1.30.0050.00317.61
8.1.20.0000.00817.63
8.1.10.0040.00417.61
8.1.00.0000.00717.54
8.0.300.0060.00320.08
8.0.290.0000.00816.75
8.0.280.0070.00018.46
8.0.270.0070.00017.23
8.0.260.0040.00417.20
8.0.250.0000.00717.07
8.0.240.0000.00816.97
8.0.230.0000.00716.90
8.0.220.0040.00416.91
8.0.210.0080.00016.93
8.0.200.0000.00616.92
8.0.190.0050.00317.03
8.0.180.0040.00416.98
8.0.170.0000.00716.86
8.0.160.0070.00017.01
8.0.150.0040.00416.93
8.0.140.0020.00516.90
8.0.130.0000.00613.34
8.0.120.0080.00016.80
8.0.110.0040.00416.94
8.0.100.0000.00716.91
8.0.90.0040.00416.76
8.0.80.0190.00416.82
8.0.70.0030.00516.99
8.0.60.0040.00416.97
8.0.50.0050.00216.71
8.0.30.0110.00717.03
8.0.20.0100.00917.40
8.0.10.0060.00317.09
8.0.00.0060.01016.84
7.4.330.0050.00015.55
7.4.320.0060.00016.45
7.4.300.0000.00616.54
7.4.290.0030.00316.68
7.4.280.0000.00716.57
7.4.270.0060.00016.54
7.4.260.0000.00716.54
7.4.250.0040.00416.61
7.4.240.0000.00716.55
7.4.230.0040.00416.74
7.4.220.0090.00716.65
7.4.210.0040.01216.58
7.4.200.0050.00316.62
7.4.160.0090.00916.56
7.4.150.0080.01117.40
7.4.140.0130.00817.86
7.4.130.0080.01116.54
7.4.120.0090.00816.50
7.4.110.0030.01516.73
7.4.100.0110.01116.52
7.4.90.0150.00316.74
7.4.80.0060.01519.39
7.4.70.0080.00816.45
7.4.60.0200.00316.50
7.4.50.0060.01016.49
7.4.40.0100.00716.54
7.4.30.0120.00316.57
7.4.10.0060.01314.90
7.4.00.0070.00915.00
7.3.330.0030.00313.24
7.3.320.0000.00613.22
7.3.310.0020.00516.34
7.3.300.0000.00716.25
7.3.290.0040.01216.36
7.3.280.0090.00916.38
7.3.270.0100.00717.40
7.3.260.0150.00516.48
7.3.250.0110.00516.48
7.3.240.0140.00316.48
7.3.230.0100.00716.42
7.3.210.0130.00316.46
7.3.200.0100.00716.59
7.3.190.0140.00516.29
7.3.180.0070.00916.52
7.3.170.0030.02016.41
7.3.160.0090.01316.48
7.3.130.0100.00614.67
7.3.120.0080.01015.04
7.3.110.0110.00714.81
7.3.100.0060.00814.80
7.3.90.0050.00614.68
7.3.80.0100.00514.80
7.3.70.0050.01014.98
7.3.60.0070.00714.96
7.3.50.0070.00514.70
7.3.40.0090.00715.01
7.3.30.0050.00814.72
7.3.20.0030.01116.71
7.3.10.0080.00616.72
7.3.00.0060.00816.63
7.2.330.0160.00316.67
7.2.320.0200.01016.80
7.2.310.0050.01316.60
7.2.300.0030.01616.58
7.2.290.0100.00716.81
7.2.260.0060.01314.89
7.2.250.0080.01015.02
7.2.240.0030.01314.92
7.2.230.0040.01014.98
7.2.220.0100.00815.25
7.2.210.0080.00515.13
7.2.200.0030.01114.97
7.2.190.0070.00815.08
7.2.180.0060.00915.08
7.2.170.0110.00414.97
7.2.160.0080.00515.32
7.2.150.0060.00616.64
7.2.140.0090.00617.00
7.2.130.0070.00717.01
7.2.120.0100.01016.75
7.2.110.0000.01216.98
7.2.100.0110.00316.73
7.2.90.0030.00917.15
7.2.80.0070.00716.70
7.2.70.0070.00716.82
7.2.60.0040.00816.87
7.2.50.0060.00816.91
7.2.40.0000.01316.83
7.2.30.0040.01417.08
7.2.20.0110.00316.92
7.2.10.0110.00416.95
7.2.00.0070.00818.13
7.1.330.0100.00315.81
7.1.320.0090.00515.76
7.1.310.0020.01115.86
7.1.300.0070.00815.56
7.1.290.0070.00615.80
7.1.280.0050.00715.83
7.1.270.0030.00815.86
7.1.260.0090.00315.63
7.1.250.0050.00815.98
7.1.240.0090.00916.07
7.1.230.0000.01015.76
7.1.220.0000.01415.84
7.1.210.0040.01115.62
7.1.200.0030.00915.93
7.1.190.0000.01615.89
7.1.180.0080.00616.02
7.1.170.0070.01115.80
7.1.160.0070.00715.77
7.1.150.0070.00715.77
7.1.140.0040.00715.87
7.1.130.0080.00815.83
7.1.120.0130.00315.97
7.1.110.0040.00815.58
7.1.100.0070.00715.58
7.1.90.0130.00315.88
7.1.80.0060.00615.90
7.1.70.0020.01016.67
7.1.60.0070.00716.38
7.1.50.0060.00615.98
7.1.40.0030.00615.52
7.1.30.0030.01015.80
7.1.20.0070.01015.71
7.1.10.0040.00815.50
7.1.00.0130.03319.13
7.0.330.0040.01215.63
7.0.320.0140.00315.43
7.0.310.0070.00715.45
7.0.300.0070.01015.51
7.0.290.0080.00615.47
7.0.280.0100.00315.60
7.0.270.0030.01415.57
7.0.260.0030.00715.30
7.0.250.0000.01015.41
7.0.240.0040.00715.35
7.0.230.0000.01315.35
7.0.220.0030.01015.31
7.0.210.0070.00715.47
7.0.200.0020.00716.07
7.0.190.0060.00615.61
7.0.180.0030.01015.27
7.0.170.0130.00015.18
7.0.160.0060.00715.36
7.0.150.0060.00315.61
7.0.140.0090.00915.18
7.0.130.0100.03718.78
7.0.120.0080.04218.73
7.0.110.0060.03118.75
7.0.100.0070.03618.60
7.0.90.0240.03718.66
7.0.80.0070.04718.71
7.0.70.0180.03318.85
7.0.60.0150.03018.65
7.0.50.0030.03718.75
7.0.40.0100.02817.76
7.0.30.0230.04517.86
7.0.20.0210.03016.91
7.0.10.0080.03717.72
7.0.00.0010.04317.84
5.6.400.0000.01114.76
5.6.390.0000.01314.73
5.6.380.0030.01014.09
5.6.370.0040.01114.60
5.6.360.0060.01214.48
5.6.350.0060.00614.32
5.6.340.0060.01014.71
5.6.330.0040.00814.39
5.6.320.0030.01014.44
5.6.310.0070.00714.48
5.6.300.0030.00714.66
5.6.290.0040.01114.60
5.6.280.0070.03217.87
5.6.270.0050.03817.83
5.6.260.0110.03817.90
5.6.250.0070.03617.86
5.6.240.0120.03817.66
5.6.230.0130.03317.87
5.6.220.0070.03217.76
5.6.210.0050.03517.58
5.6.200.0130.04117.59
5.6.190.0050.03717.65
5.6.180.0070.03417.73
5.6.170.0070.02917.79
5.6.160.0080.03117.62
5.6.150.0100.03217.64
5.6.140.0080.04417.69
5.6.130.0080.03217.73
5.6.120.0120.03217.57
5.6.110.0080.04017.77
5.6.100.0140.02717.61
5.6.90.0040.04617.60
5.6.80.0100.03717.40
5.6.70.0090.02817.40
5.6.60.0060.03517.26
5.6.50.0050.03417.39
5.6.40.0150.02817.12
5.6.30.0020.03717.27
5.6.20.0080.02817.23
5.6.10.0080.03117.30
5.6.00.0100.03117.21

preferences:
44.35 ms | 401 KiB | 5 Q