3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array( 42 => 10, 55 => 20, 56 => 10, 57 => 4, 58 => 5, 59 => 240, 60 => 123, ); // Can we do all in one subarray? if(array_sum($arr) >= 250){ //No $sum = 0; $index = 0; $result[$index] =[]; //Loop the array and keep the sum in memory foreach($arr as $key => $val){ if($sum + $val < 250){ //Less than 250, just keep adding the values $result[$index]['values'][] = $val; $result[$index]['elements'][] = $key; $sum += $val; }else{ // More than 250, create a new subarray and reset sum $sum = $val; $index++; $result[$index] = ['values' => [$val], 'elements' => [$key]]; } } }else{ //Yes, group the values and keys $result = [['values' => array_values($arr), 'elements' => array_keys($arr)]]; } var_dump($result);

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.130.0130.00817.65
8.4.120.0120.01020.13
8.4.110.0100.01122.42
8.4.100.0110.01017.61
8.4.90.0110.00920.39
8.4.80.0130.00717.87
8.4.70.0080.00117.91
8.4.60.0110.00924.06
8.4.50.0140.00618.44
8.4.40.0060.00319.37
8.4.30.0040.00424.07
8.4.20.0100.01020.41
8.4.10.0060.00317.62
8.3.260.0160.00416.49
8.3.250.0110.00918.90
8.3.240.0050.00316.64
8.3.230.0080.00816.77
8.3.220.0100.00719.00
8.3.210.0090.00518.48
8.3.200.0050.00616.88
8.3.190.0110.00817.02
8.3.180.0120.00616.61
8.3.170.0120.00617.41
8.3.160.0070.01018.48
8.3.150.0130.00616.58
8.3.140.0120.00617.34
8.3.130.0080.00018.47
8.3.120.0090.00019.19
8.3.110.0080.00018.35
8.3.100.0080.01218.40
8.3.90.0090.00626.77
8.3.80.0090.00016.68
8.3.70.0120.00616.63
8.3.60.0120.00318.55
8.3.50.0110.01022.00
8.3.40.0100.01018.83
8.3.30.0110.00418.67
8.3.20.0000.00821.60
8.3.10.0040.00420.16
8.3.00.0070.00023.66
8.2.290.0100.00716.56
8.2.280.0110.00818.40
8.2.270.0140.00416.98
8.2.260.0000.00816.78
8.2.250.0090.00916.41
8.2.240.0060.00316.49
8.2.230.0030.00620.94
8.2.220.0040.00424.06
8.2.210.0000.00926.77
8.2.200.0080.00016.75
8.2.190.0140.00416.63
8.2.180.0040.01116.38
8.2.170.0110.00422.96
8.2.160.0110.00420.94
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0070.00026.16
8.2.120.0000.00826.16
8.2.110.0030.00619.18
8.2.100.0110.00019.45
8.2.90.0070.00417.91
8.2.80.0000.00817.97
8.2.70.0030.00618.05
8.2.60.0000.00918.22
8.2.50.0090.00018.10
8.2.40.0080.00019.33
8.2.30.0040.00419.34
8.2.20.0070.00018.00
8.2.10.0040.00419.21
8.2.00.0000.00719.18
8.1.330.0130.00620.17
8.1.320.0120.00716.07
8.1.310.0080.00318.45
8.1.300.0030.00616.16
8.1.290.0060.00330.84
8.1.280.0140.00025.92
8.1.270.0030.00522.05
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00622.07
8.1.230.0090.00320.89
8.1.220.0000.00917.74
8.1.210.0050.00318.77
8.1.200.0070.00617.48
8.1.190.0030.00617.48
8.1.180.0080.00018.10
8.1.170.0040.00418.57
8.1.160.0080.00018.76
8.1.150.0040.00418.76
8.1.140.0000.00718.93
8.1.130.0030.00317.47
8.1.120.0030.00617.43
8.1.110.0040.00417.50
8.1.100.0030.00517.44
8.1.90.0030.00317.36
8.1.80.0090.00017.45
8.1.70.0000.00817.35
8.1.60.0040.00417.47
8.1.50.0000.00817.48
8.1.40.0050.00517.52
8.1.30.0060.00317.50
8.1.20.0030.00617.50
8.1.10.0000.00817.57
8.1.00.0040.00417.36
8.0.300.0040.00420.04
8.0.290.0050.00316.63
8.0.280.0000.00718.35
8.0.270.0040.00416.81
8.0.260.0040.00416.77
8.0.250.0100.00016.96
8.0.240.0030.00316.98
8.0.230.0030.00316.88
8.0.220.0000.00716.78
8.0.210.0040.00216.88
8.0.200.0000.00616.92
8.0.190.0040.00416.95
8.0.180.0000.00716.94
8.0.170.0000.00816.90
8.0.160.0000.00716.92
8.0.150.0050.00316.83
8.0.140.0070.00016.86
8.0.130.0000.00513.34
8.0.120.0040.00416.82
8.0.110.0000.00716.82
8.0.100.0050.00216.93
8.0.90.0000.00916.95
8.0.80.0030.01716.94
8.0.70.0040.00416.85
8.0.60.0070.00016.95
8.0.50.0000.00716.95
8.0.30.0090.00917.21
8.0.20.0100.01116.86
8.0.10.0020.00516.91
8.0.00.0040.01616.83
7.4.330.0020.00215.55
7.4.320.0040.00416.52
7.4.300.0000.00716.59
7.4.290.0040.00416.53
7.4.280.0070.00216.40
7.4.270.0050.00516.65
7.4.260.0040.00416.65
7.4.250.0040.00416.45
7.4.240.0020.00516.56
7.4.230.0050.00316.65
7.4.220.0000.00716.62
7.4.210.0080.01116.54
7.4.200.0070.00016.50
7.4.130.0110.00816.58
7.4.120.0130.01016.52
7.4.110.0070.01116.55
7.4.100.0040.02116.48
7.4.90.0110.00716.55
7.4.80.0150.00319.39
7.4.70.0070.01016.59
7.4.60.0160.00516.56
7.4.50.0070.00716.36
7.4.40.0130.00416.34
7.4.00.0040.01214.93
7.3.330.0000.00613.16
7.3.320.0060.00013.25
7.3.310.0070.00016.28
7.3.300.0060.00016.20
7.3.290.0000.00716.34
7.3.280.0060.00916.35
7.3.260.0110.00916.43
7.3.230.0100.01016.45
7.3.210.0180.00416.28
7.3.200.0060.01116.64
7.3.190.0110.00716.62
7.3.180.0110.00616.60
7.3.170.0070.01016.33
7.3.160.0170.00016.36
7.3.70.0070.01514.79
7.3.60.0070.00714.93
7.3.50.0180.00414.94
7.3.40.0130.00714.57
7.3.30.0070.01414.80
7.3.20.0120.00314.55
7.3.10.0110.00314.86
7.3.00.0040.01114.80
7.2.330.0060.01216.76
7.2.320.0090.00916.88
7.2.310.0120.00616.61
7.2.300.0100.00716.46
7.2.290.0100.00716.70
7.2.200.0110.01114.97
7.2.190.0100.00315.20
7.2.180.0070.01415.34
7.2.170.0050.00714.93
7.2.160.0080.00814.91
7.2.150.0100.01415.21
7.2.140.0120.00314.82
7.2.130.0060.00915.18
7.2.120.0070.00715.18
7.2.110.0120.01415.08
7.2.100.0110.00415.28
7.2.90.0030.01215.13
7.2.80.0150.00615.08
7.2.70.0150.00615.10
7.2.60.0140.00715.21
7.2.50.1050.00915.05
7.2.40.0100.01015.04
7.2.30.0170.01015.19
7.2.20.0140.01414.99
7.2.10.0090.01515.27
7.2.00.0250.00415.25
7.1.300.0180.00413.96
7.1.290.0180.00613.80
7.1.280.0150.00714.08
7.1.270.0180.00313.71
7.1.260.0040.01113.73
7.1.250.0030.01013.64

preferences:
30.2 ms | 403 KiB | 5 Q