3v4l.org

run code in 300+ PHP versions simultaneously
<?php function merge(array ...$sets) { /** * group contributions by name */ $contributions = array_reduce( $sets, function (array $contributions, array $set) { foreach ($set as $element) { $name = $element['P_Name']; $contribution = $element['Contribution']; if (!array_key_exists($name, $contributions)) { $contributions[$name] = []; } $contributions[$name][] = $contribution; } return $contributions; }, [] ); /** * normalize the array so we remove the name as key, and return a tuple of name and contribution, with the desired * structure */ return array_values(array_map(function (array $contribution, $name) { return [ 'Contribution' => array_sum($contribution), 'P_Name' => $name, ]; }, $contributions, array_keys($contributions))); } $a = [ [ 'Contribution' => 1000, 'P_Name' => 'A', ], [ 'Contribution' => 1500, 'P_Name' => 'B', ], ]; $b = [ [ 'Contribution' => 100, 'P_Name' => 'A', ], [ 'Contribution' => 200, 'P_Name' => 'B', ], ]; $merged = merge($a, $b); var_dump($merged);

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.0210.00016.88
8.3.50.0030.01016.39
8.3.40.0090.00618.77
8.3.30.0100.00718.82
8.3.20.0030.00520.22
8.3.10.0090.00020.90
8.3.00.0040.00420.14
8.2.180.0150.00616.88
8.2.170.0040.01122.96
8.2.160.0070.01019.15
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0100.00726.16
8.2.120.0040.00420.75
8.2.110.0140.00320.40
8.2.100.0090.00317.91
8.2.90.0030.00519.21
8.2.80.0000.00817.97
8.2.70.0000.00817.75
8.2.60.0000.00917.63
8.2.50.0000.00917.63
8.2.40.0000.00819.35
8.2.30.0000.00819.36
8.2.20.0000.00718.10
8.2.10.0000.00718.20
8.2.00.0040.00418.20
8.1.280.0070.00725.92
8.1.270.0030.00523.99
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0040.00420.88
8.1.230.0080.00420.98
8.1.220.0000.00817.74
8.1.210.0030.00518.77
8.1.200.0060.00317.35
8.1.190.0040.00417.23
8.1.180.0080.00018.10
8.1.170.0030.00517.68
8.1.160.0000.00718.97
8.1.150.0030.00520.31
8.1.140.0070.00019.67
8.1.130.0000.00718.95
8.1.120.0070.00417.49
8.1.110.0000.00817.52
8.1.100.0030.00517.56
8.1.90.0030.00517.41
8.1.80.0040.00417.54
8.1.70.0040.00417.39
8.1.60.0000.00717.69
8.1.50.0040.00417.54
8.1.40.0030.00517.46
8.1.30.0000.00817.53
8.1.20.0040.00417.70
8.1.10.0050.00317.61
8.1.00.0000.01017.37
8.0.300.0070.00018.77
8.0.290.0000.00916.88
8.0.280.0040.00418.54
8.0.270.0000.00717.18
8.0.260.0000.00718.85
8.0.250.0040.00216.91
8.0.240.0000.00716.96
8.0.230.0100.00017.02
8.0.220.0050.00216.83
8.0.210.0150.00016.82
8.0.200.0030.00316.98
8.0.190.0030.00516.96
8.0.180.0040.00417.00
8.0.170.0030.00316.82
8.0.160.0080.00017.06
8.0.150.0030.00516.98
8.0.140.0050.00216.85
8.0.130.0030.00313.27
8.0.120.0040.00416.80
8.0.110.0000.00716.91
8.0.100.0040.00416.97
8.0.90.0040.00416.88
8.0.80.0150.00616.90
8.0.70.0050.00316.86
8.0.60.0040.00416.88
8.0.50.0000.00716.82
8.0.30.0100.00817.19
8.0.20.0100.01017.42
8.0.10.0080.00016.91
8.0.00.0090.00916.89
7.4.330.0000.00615.55
7.4.320.0000.00616.41
7.4.300.0000.00616.50
7.4.290.0030.00316.63
7.4.280.0000.00716.44
7.4.270.0000.00716.54
7.4.260.0030.00316.43
7.4.250.0000.00716.50
7.4.240.0030.00316.56
7.4.230.0030.00316.46
7.4.220.0100.00916.44
7.4.210.0090.00616.61
7.4.200.0000.00716.63
7.4.160.0150.00416.54
7.4.150.0110.00617.40
7.4.140.0110.01117.86
7.4.130.0070.01116.53
7.4.120.0110.01016.67
7.4.110.0090.00816.52
7.4.100.0100.01016.33
7.4.90.0070.01016.54
7.4.80.0060.01219.39
7.4.70.0040.01416.41
7.4.60.0080.00816.50
7.4.50.0070.00716.39
7.4.40.0080.00816.45
7.4.30.0080.00816.57
7.4.00.0000.01715.08
7.3.330.0030.00313.31
7.3.320.0000.00513.41
7.3.310.0050.00316.38
7.3.300.0070.00016.24
7.3.290.0070.00716.39
7.3.280.0080.00816.38
7.3.270.0100.01017.40
7.3.260.0150.01916.38
7.3.250.0060.01616.43
7.3.240.0120.00616.53
7.3.230.0140.00316.60
7.3.210.0070.01116.37
7.3.200.0090.00616.38
7.3.190.0080.00816.36
7.3.180.0150.00916.66
7.3.170.0100.00716.41
7.3.160.0070.01016.55
7.2.330.0040.01916.86
7.2.320.0150.00416.85
7.2.310.0000.02216.39
7.2.300.0030.01316.52
7.2.290.0140.00316.78
7.2.60.0000.01016.93
7.1.200.0000.01215.86
7.1.90.0300.00715.99
7.1.80.0250.00616.18
7.1.70.0220.00615.30
7.1.60.0320.01333.36
7.1.50.0340.00632.78
7.1.40.0270.01432.70
7.1.30.0320.00932.61
7.1.20.0380.00632.79
7.1.10.0210.00914.57
7.1.00.0210.01114.93
7.0.200.0920.00315.16
7.0.190.0170.01014.85
7.0.180.0180.00914.46
7.0.170.0190.01014.44
7.0.160.0220.00714.45
7.0.150.0230.00814.55
7.0.140.0200.01014.48
7.0.130.0340.01714.95
7.0.120.0320.00914.82
7.0.110.0390.01614.61
7.0.100.0390.00714.46
7.0.90.0300.00414.50
7.0.80.0270.01014.79
7.0.70.0270.01014.47
7.0.60.0290.00314.37
7.0.50.0240.00714.80
7.0.40.0250.00614.64
7.0.30.0250.01914.71
7.0.20.0200.01314.68
7.0.10.0240.00714.85
7.0.00.0270.01014.55

preferences:
50.55 ms | 400 KiB | 5 Q