3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ '5' => [ 'BG' => 50, 'CH' => 60, 'LG' => 50, 'MT' => 40, 'MO' => 80, 'PH' => 60, 'GE' => null, ], ], [ '6' => [ 'BG' => 90, 'CH' => 60, 'LG' => 60, 'MT' => 50, 'MO' => null, 'PH' => 50, 'GE' => null, ], ], [ '7' => [ 'BG' => 80, 'CH' => 55, 'LG' => 65, 'MT' => 50, 'MO' => null, 'PH' => 50, 'GE' => 55, ], ], ]; $keys = array_flip(['BG', 'MT', 'GE']); // best of two keys $Ckeys = array_flip(['CH', 'PH', 'MO', 'LG']); // compulsory keys foreach ($arr as $key => $value) { // use to pass parameters to reduce function during call $temp[key($value)] = array_reduce($value, function (&$result, $a) use ($keys, $Ckeys) { // if mo empty then best of two else best of one $bestHowMany = (!empty($a['MO']) ? 1 : 2); // fetching best of keys from $keys $t = array_intersect_key($a, $keys); // reverse sort and maintains keys arsort($t); // fetch top $bestHowMany Values $largest2 = array_slice($t, 0, $bestHowMany); // fetch compulsory values from CKeys $t1 = array_intersect_key($a, $Ckeys); // sum by merging compulsory and best of $bestHowMany values return array_sum(array_merge($t1, $largest2)); }); } print_r($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.4.130.0130.00717.89
8.4.120.0050.00422.39
8.4.110.0050.00522.39
8.4.100.0100.01019.63
8.4.90.0120.00918.47
8.4.80.0110.01019.91
8.4.70.0090.01018.01
8.4.60.0150.00618.78
8.4.50.0120.00618.49
8.4.40.0130.00718.70
8.4.30.0130.00020.71
8.4.20.0130.00720.66
8.4.10.0040.00419.97
8.3.260.0130.00616.80
8.3.250.0100.00619.11
8.3.240.0110.01018.75
8.3.230.0190.00516.70
8.3.220.0110.00717.29
8.3.210.0100.01018.64
8.3.200.0040.00516.67
8.3.190.0110.00416.98
8.3.180.0060.00216.90
8.3.170.0050.00320.86
8.3.160.0040.00418.42
8.3.150.0150.00417.21
8.3.140.0080.00018.41
8.3.130.0040.00418.74
8.3.120.0030.00620.77
8.3.110.0130.00316.66
8.3.100.0130.00316.66
8.3.90.0000.00826.77
8.3.80.0060.00316.75
8.3.70.0160.00018.50
8.3.60.0070.00718.15
8.3.50.0090.01116.47
8.3.40.0090.00618.92
8.3.30.0080.00818.71
8.3.20.0000.00821.02
8.3.10.0050.00320.18
8.3.00.0050.00323.61
8.2.290.0140.00520.51
8.2.280.0150.00518.55
8.2.270.0060.01217.39
8.2.260.0150.00018.82
8.2.250.0060.00316.99
8.2.240.0120.00418.77
8.2.230.0100.00020.94
8.2.220.0080.00037.54
8.2.210.0090.00626.77
8.2.200.0090.00018.41
8.2.190.0100.00716.63
8.2.180.0090.00616.63
8.2.170.0070.00722.96
8.2.160.0070.00720.39
8.2.150.0030.00624.18
8.2.140.0080.00024.66
8.2.130.0050.00226.16
8.2.120.0050.00319.49
8.2.110.0030.00719.33
8.2.100.0040.00817.84
8.2.90.0030.00520.42
8.2.80.0030.00518.22
8.2.70.0080.00018.05
8.2.60.0040.00418.34
8.2.50.0060.00318.10
8.2.40.0040.00419.30
8.2.30.0000.00819.36
8.2.20.0060.00318.16
8.2.10.0050.00320.66
8.2.00.0030.00319.45
8.1.330.0130.00522.14
8.1.320.0050.00416.34
8.1.310.0040.00418.34
8.1.300.0060.00319.37
8.1.290.0000.01130.84
8.1.280.0120.00925.92
8.1.270.0050.00322.63
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0000.00921.96
8.1.230.0110.00020.89
8.1.220.0080.00017.77
8.1.210.0090.00019.04
8.1.200.0030.00617.35
8.1.190.0030.00517.23
8.1.180.0060.00318.10
8.1.170.0060.00318.46
8.1.160.0000.00819.03
8.1.150.0000.00718.88
8.1.140.0050.00218.89
8.1.130.0000.00817.35
8.1.120.0000.00817.40
8.1.110.0000.00817.50
8.1.100.0040.00517.49
8.1.90.0040.00717.54
8.1.80.0050.00517.46
8.1.70.0070.00017.49
8.1.60.0050.00317.57
8.1.50.0040.00417.57
8.1.40.0060.00317.42
8.1.30.0030.00517.69
8.1.20.0030.00517.64
8.1.10.0000.00717.66
8.1.00.0110.00017.45
8.0.300.0070.00020.05
8.0.290.0070.00016.75
8.0.280.0030.00318.52
8.0.270.0000.00816.99
8.0.260.0030.00316.82
8.0.250.0030.00316.97
8.0.240.0030.00316.92
8.0.230.0030.00617.08
8.0.220.0030.00316.92
8.0.210.0070.00017.05
8.0.200.0000.00717.04
8.0.190.0080.00017.06
8.0.180.0040.00417.03
8.0.170.0090.00316.91
8.0.160.0040.00417.07
8.0.150.0080.00016.93
8.0.140.0040.00416.93
8.0.130.0060.00013.47
8.0.120.0030.00616.85
8.0.110.0040.00417.00
8.0.100.0040.00417.07
8.0.90.0040.00416.97
8.0.80.0100.00916.90
8.0.70.0000.00716.97
8.0.60.0070.00016.93
8.0.50.0030.00516.98
8.0.30.0100.00617.09
8.0.20.0090.00917.18
8.0.10.0000.00817.16
8.0.00.0110.00916.81
7.4.330.0050.00015.55
7.4.320.0060.00016.44
7.4.300.0000.00716.53
7.4.290.0000.00816.63
7.4.280.0050.00316.67
7.4.270.0040.00416.64
7.4.260.0030.00316.46
7.4.250.0040.00416.64
7.4.240.0040.00416.45
7.4.230.0030.00316.73
7.4.220.0030.00516.73
7.4.210.0050.01216.57
7.4.200.0040.00416.54
7.4.160.0120.00716.47
7.4.130.0160.00016.63
7.4.120.0090.01216.56
7.4.110.0170.00416.69
7.4.100.0140.00816.37
7.4.90.0040.01816.39
7.4.80.0060.01719.39
7.4.70.0120.00616.43
7.4.60.0090.00616.66
7.4.50.0030.01316.40
7.4.40.0070.01316.48
7.4.00.0090.00915.11
7.3.330.0060.00013.34
7.3.320.0000.00513.20
7.3.310.0050.00216.25
7.3.300.0000.00716.29
7.3.290.0140.00716.45
7.3.280.0200.00016.40
7.3.260.0100.01016.44
7.3.240.0130.00316.47
7.3.230.0200.00316.38
7.3.210.0090.00916.44
7.3.200.0060.01016.42
7.3.190.0140.00416.42
7.3.180.0120.00616.68
7.3.170.0060.01616.49
7.3.160.0110.00516.54
7.3.120.0070.00914.81
7.3.110.0090.00914.89
7.3.100.0070.01214.78
7.3.90.0050.00814.86
7.3.80.0040.01314.78
7.3.70.0050.01014.83
7.3.60.0070.00714.84
7.3.50.0070.00514.78
7.3.40.0050.01114.84
7.3.30.0080.00314.74
7.3.20.0090.00716.16
7.3.10.0080.00816.04
7.3.00.0100.00816.08
7.2.330.0110.00716.41
7.2.320.0100.01016.69
7.2.310.0110.00716.78
7.2.300.0090.01516.46
7.2.290.0120.00416.77
7.2.250.0050.01415.25
7.2.240.0100.00915.02
7.2.230.0050.01014.67
7.2.220.0070.00614.99
7.2.210.0050.01315.14
7.2.200.0050.00715.04
7.2.190.0040.01314.99
7.2.180.0060.00814.97
7.2.170.0060.00914.96
7.2.160.0050.00715.07
7.2.150.0060.00916.25
7.2.140.0100.00616.34
7.2.130.0050.00816.36
7.2.120.0060.01316.40
7.2.110.0080.00616.32
7.2.100.0100.00716.36
7.2.90.0090.00916.22
7.2.80.0360.00816.29
7.2.70.0060.01216.44
7.2.60.0140.00716.28
7.2.50.0080.00816.30
7.2.40.0090.00816.19
7.2.30.0140.00616.29
7.2.20.0080.00616.20
7.2.10.0110.00316.33
7.2.00.0130.00816.32
7.1.330.0090.00715.55
7.1.320.0050.00915.82
7.1.310.0040.00915.93
7.1.300.0020.01215.92
7.1.290.0060.00615.84
7.1.280.0040.00815.29
7.1.270.0070.00815.18
7.1.260.0080.01015.20
7.1.250.0040.00815.20
7.1.240.0030.01015.61
7.1.230.0070.00415.95
7.1.220.0060.01015.63
7.1.210.0060.00615.95
7.1.200.0040.00716.01
7.1.190.0060.00915.70
7.1.180.0030.01015.78
7.1.170.0070.00315.80
7.1.160.0060.00915.68
7.1.150.0040.00815.70
7.1.140.0070.00315.65
7.1.130.0030.01015.56
7.1.120.0060.00315.87
7.1.110.0060.00915.98
7.1.100.0070.00715.75
7.1.90.0040.01116.02
7.1.80.0070.01015.88
7.1.70.0130.00315.85
7.1.60.0080.00615.78
7.1.50.0000.01515.67
7.1.40.0030.01015.84
7.1.30.0090.00615.87
7.1.20.0030.01015.71
7.1.10.0070.01015.75
7.1.00.0090.00315.53

preferences:
28.15 ms | 403 KiB | 5 Q