3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [11, 3, 45, 6, 61, 89, 22]; function array_slimmer(array $array, int $finalCount): array { // no work to be done if we're asking for more than what the array holds // same goes if we're asking for just one array or (nonsensical) less if ($finalCount >= count($array) || $finalCount < 2) { return $array; } return array_map(function (array $chunk) { // rounded to two decimals, but you can modify to accomodate your needs return round(array_sum($chunk) / count($chunk), 2); }, custom_chunk($array, $finalCount)); } function custom_chunk($array, $maxrows) { $size = sizeof($array); $columns = ceil($size / $maxrows); $fullrows = $size - ($columns - 1) * $maxrows; for ($i = 0; $i < $maxrows; ++$i) { $result[] = array_splice($array, 0, ($i < $fullrows ? $columns : $columns - 1)); } return $result; } print_r(array_slimmer($array, 2)); print_r(array_slimmer($array, 3)); print_r(array_slimmer($array, 4));

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.5.10.0110.00816.80
8.5.00.0140.00820.18
8.4.150.0020.00014.05
8.4.140.0130.00817.34
8.4.130.0090.01118.79
8.4.120.0110.00824.15
8.4.110.0140.00618.78
8.4.100.0100.01018.83
8.4.90.0120.01020.80
8.4.80.0060.00618.65
8.4.70.0060.00417.87
8.4.60.0160.01019.04
8.4.50.0110.00920.25
8.4.40.0120.00817.72
8.4.30.0080.00018.61
8.4.20.0130.00617.39
8.4.10.0040.00419.56
8.3.280.0120.00818.50
8.3.270.0120.00916.83
8.3.260.0100.00816.66
8.3.250.0100.00619.09
8.3.240.0080.00517.22
8.3.230.0110.00816.77
8.3.220.0040.00419.00
8.3.210.0100.00716.44
8.3.200.0050.00716.50
8.3.190.0080.00916.81
8.3.180.0110.00918.23
8.3.170.0140.00417.08
8.3.160.0090.00916.43
8.3.150.0150.00420.55
8.3.140.0100.00717.10
8.3.130.0040.00418.59
8.3.120.0030.00619.16
8.3.110.0150.00018.32
8.3.100.0110.00718.71
8.3.90.0040.00418.45
8.3.80.0030.00617.97
8.3.70.0110.01118.43
8.3.60.0140.00416.63
8.3.50.0050.01123.63
8.3.40.0140.00719.17
8.3.30.0040.01118.79
8.3.20.0030.00522.02
8.3.10.0040.00422.22
8.3.00.0040.00423.79
8.2.290.0100.00820.79
8.2.280.0120.00618.43
8.2.270.0090.00917.16
8.2.260.0140.00416.50
8.2.250.0080.00016.98
8.2.240.0100.01016.89
8.2.230.0000.00720.94
8.2.220.0090.00924.06
8.2.210.0050.00226.77
8.2.200.0050.00518.29
8.2.190.0040.01216.72
8.2.180.0140.00716.63
8.2.170.0120.00619.04
8.2.160.0070.00722.96
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0050.00321.00
8.2.110.0060.00621.18
8.2.100.0070.00417.97
8.2.90.0030.00617.63
8.2.80.0000.00818.92
8.2.70.0000.00818.18
8.2.60.0000.00718.28
8.2.50.0050.00319.25
8.2.40.0000.00821.32
8.2.30.0070.00019.27
8.2.20.0000.00718.08
8.2.10.0050.00319.64
8.2.00.0080.00019.27
8.1.330.0090.01022.09
8.1.320.0130.00617.64
8.1.310.0040.00416.61
8.1.300.0030.00618.66
8.1.290.0060.00318.88
8.1.280.0090.00925.92
8.1.270.0030.00523.96
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0100.00022.66
8.1.230.0000.01121.06
8.1.220.0050.00317.80
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0070.00019.04
8.1.170.0030.00518.52
8.1.160.0040.00419.09
8.1.150.0000.00719.03
8.1.140.0060.00319.02
8.1.130.0000.00720.12
8.1.120.0040.00417.59
8.1.110.0030.00617.56
8.1.100.0030.00617.55
8.1.90.0000.00717.54
8.1.80.0040.00417.48
8.1.70.0030.00317.56
8.1.60.0000.00917.59
8.1.50.0050.00217.61
8.1.40.0000.00817.55
8.1.30.0030.00517.72
8.1.20.0030.00617.66
8.1.10.0030.00617.72
8.1.00.0000.00817.55
8.0.300.0040.00418.77
8.0.290.0030.00616.63
8.0.280.0000.00718.56
8.0.270.0070.00016.91
8.0.260.0040.00418.45
8.0.250.0030.00317.09
8.0.240.0000.00716.93
8.0.230.0040.00417.02
8.0.220.0000.00716.95
8.0.210.0080.00016.97
8.0.200.0040.00417.05
8.0.190.0000.00717.04
8.0.180.0000.00816.88
8.0.170.0000.00916.93
8.0.160.0030.00317.03
8.0.150.0070.00316.98
8.0.140.0070.00316.82
8.0.130.0000.00613.38
8.0.120.0030.00516.86
8.0.110.0040.00417.02
8.0.100.0040.00417.02
8.0.90.0040.00416.94
8.0.80.0090.00716.97
8.0.70.0000.00817.01
8.0.60.0000.00717.03
8.0.50.0000.00716.80
8.0.30.0130.00316.92
8.0.20.0120.00717.01
8.0.10.0050.00316.98
8.0.00.0060.01117.02
7.4.330.0070.00015.55
7.4.320.0000.00816.69
7.4.300.0060.00016.57
7.4.290.0070.00016.52
7.4.280.0080.00016.61
7.4.270.0070.00016.57
7.4.260.0030.00313.32
7.4.250.0080.00016.54
7.4.240.0040.00316.71
7.4.230.0000.00716.69
7.4.220.0020.00516.61
7.4.210.0090.01116.65
7.4.200.0000.00716.65
7.4.130.0090.00816.60
7.4.120.0120.00616.57
7.4.110.0090.00916.63
7.4.100.0130.01016.48
7.4.90.0070.01016.63
7.4.80.0060.01219.39
7.4.70.0120.00616.77
7.4.60.0030.01216.48
7.4.50.0040.01116.53
7.4.40.0070.01416.41
7.4.30.0120.00416.62
7.4.20.0050.01716.60
7.4.10.0070.01516.71
7.4.00.0100.01316.54
7.3.330.0000.00816.33
7.3.320.0050.00013.52
7.3.310.0070.00016.44
7.3.300.0000.00716.30
7.3.290.0080.00916.40
7.3.280.0090.00616.40
7.3.260.0120.00616.86
7.3.240.0090.01116.64
7.3.230.0120.00616.41
7.3.210.0150.00916.55
7.3.200.0060.01516.51
7.3.190.0070.01016.46
7.3.180.0190.00316.35
7.3.170.0060.01116.55
7.3.160.0090.00916.39
7.3.150.0130.00416.62
7.3.140.0090.00916.40
7.3.130.0060.01216.78
7.3.120.0090.00616.32
7.3.110.0100.00616.59
7.3.100.0060.01016.61
7.3.90.0080.00816.50
7.3.80.0080.00816.48
7.3.70.0120.00616.40
7.3.60.0070.01016.46
7.3.50.0110.00516.39
7.3.40.0030.01316.39
7.3.30.0100.01316.57
7.3.20.0090.00916.46
7.3.10.0090.00916.64
7.3.00.0070.01416.43
7.2.330.0090.00916.91
7.2.320.0160.00316.63
7.2.310.0100.00716.95
7.2.300.0090.01516.68
7.2.290.0120.00616.62
7.2.280.0140.00316.81
7.2.270.0110.00616.76
7.2.260.0060.01216.84
7.2.250.0090.00916.82
7.2.240.0120.00616.67
7.2.230.0120.00416.55
7.2.220.0070.01116.52
7.2.210.0030.01416.59
7.2.200.0060.01416.68
7.2.190.0070.01016.82
7.2.180.0070.01016.71
7.2.170.0060.01116.71
7.2.160.0030.01816.78
7.2.150.0140.00316.76
7.2.140.0060.01216.79
7.2.130.0170.01016.94
7.2.120.0110.00716.70
7.2.110.0090.01016.88
7.2.100.0060.01616.79
7.2.90.0070.01616.73
7.2.80.0080.01516.63
7.2.70.0110.01116.93
7.2.60.0070.01116.70
7.2.50.0110.00716.67
7.2.40.0060.01216.81
7.2.30.0000.01816.88
7.2.20.0070.01016.81
7.2.10.0140.00316.82
7.2.00.0130.00616.77

preferences:
177.59 ms | 403 KiB | 5 Q