3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sumArray($array, $index, $col) { $returnArray = []; // temporary container // sanity checks if (!is_array($array)) { return 'error not an array'; } $firstRow = reset($array); if (!array_key_exists($index, $firstRow) || !array_key_exists($col, $firstRow)) { return 'error keys provided not found'; } foreach ($array as $value) { if (!isset($returnArray[$value[$index]])) { // initialize $returnArray[$value[$index]] = [$index => $value[$index], $col => 0]; } // add value $returnArray[$value[$index]][$col] += $value[$col]; } return $returnArray; } $products = array ( array("Id" => "000001", "Name" => "Cheese", "Quantity" => "10", "Price" => "10"), array("Id" => "000001", "Name" => "Cheese", "Quantity" => "20", "Price" => "20"), array("Id" => "000001", "Name" => "Cheese", "Quantity" => "10", "Price" => "30"), array("Id" => "000002", "Name" => "Ham", "Quantity" => "20", "Price" => "200"), array("Id" => "000002", "Name" => "Ham", "Quantity" => "9", "Price" => "100"), array("Id" => "000003", "Name" => "Baicon", "Quantity" => "40", "Price" => "900") ); $summedArray = sumArray($products, 'Id', 'Quantity'); print_r($summedArray);

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.120.0090.00424.43
8.4.110.0110.00920.67
8.4.100.0130.00920.69
8.4.90.0060.00418.98
8.4.80.0130.00718.75
8.4.70.0100.00917.68
8.4.60.0110.01118.42
8.4.50.0110.00918.90
8.4.40.0160.00317.45
8.4.30.0100.00717.73
8.4.20.0070.01319.59
8.4.10.0170.00317.75
8.3.250.0090.01018.88
8.3.240.0120.00717.09
8.3.230.0130.00816.56
8.3.220.0120.00618.92
8.3.210.0080.01016.72
8.3.200.0060.00316.35
8.3.190.0070.01116.45
8.3.180.0040.00416.84
8.3.170.0190.00018.97
8.3.160.0050.00516.65
8.3.150.0110.00718.92
8.3.140.0040.00416.81
8.3.130.0000.00918.49
8.3.120.0040.00420.83
8.3.110.0100.00720.94
8.3.100.0060.00316.49
8.3.90.0070.00726.77
8.3.80.0030.00618.31
8.3.70.0030.01416.63
8.3.60.0090.00616.75
8.3.50.0070.00617.34
8.3.40.0110.00418.73
8.3.30.0090.00618.63
8.3.20.0040.00422.08
8.3.10.0040.00421.85
8.3.00.0050.00221.86
8.2.290.0110.00820.29
8.2.280.0060.00618.61
8.2.270.0070.01117.33
8.2.260.0110.00316.72
8.2.250.0200.00718.14
8.2.240.0050.00518.90
8.2.230.0030.00622.58
8.2.220.0040.00424.06
8.2.210.0090.00926.77
8.2.200.0030.00718.29
8.2.190.0060.01017.00
8.2.180.0040.01218.41
8.2.170.0090.00622.96
8.2.160.0000.01420.54
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0070.00026.16
8.2.120.0000.00819.96
8.2.110.0030.00621.04
8.2.100.0070.00418.22
8.2.90.0040.00417.88
8.2.80.0050.00518.79
8.2.70.0040.00718.03
8.2.60.0040.00418.05
8.2.50.0030.00618.22
8.2.40.0040.00420.63
8.2.30.0000.00719.39
8.2.20.0080.00018.03
8.2.10.0000.00718.09
8.2.00.0000.00718.20
8.1.330.0060.00222.22
8.1.320.0120.00916.14
8.1.310.0090.00916.84
8.1.300.0060.00318.33
8.1.290.0050.00530.84
8.1.280.0140.00025.92
8.1.270.0050.00323.83
8.1.260.0130.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00622.00
8.1.230.0040.00821.03
8.1.220.0060.00317.74
8.1.210.0040.00418.77
8.1.200.0040.00417.36
8.1.190.0060.00617.23
8.1.180.0080.00018.10
8.1.170.0000.00818.86
8.1.160.0000.00718.84
8.1.150.0030.00519.07
8.1.140.0040.00417.77
8.1.130.0050.00318.96
8.1.120.0050.00217.52
8.1.110.0040.00417.50
8.1.100.0000.00717.43
8.1.90.0000.00717.50
8.1.80.0000.00717.42
8.1.70.0000.00817.46
8.1.60.0090.00017.50
8.1.50.0000.00917.52
8.1.40.0030.00617.59
8.1.30.0050.00317.67
8.1.20.0040.00417.66
8.1.10.0030.00617.45
8.1.00.0070.00417.41
8.0.300.0030.00519.46
8.0.290.0040.00416.63
8.0.280.0020.00518.42
8.0.270.0030.00517.17
8.0.260.0070.00018.91
8.0.250.0030.00317.02
8.0.240.0040.00417.07
8.0.230.0080.00016.98
8.0.220.0040.00416.94
8.0.210.0070.00016.91
8.0.200.0030.00316.91
8.0.190.0080.00016.95
8.0.180.0070.00016.81
8.0.170.0000.00916.89
8.0.160.0040.00416.98
8.0.150.0030.00616.86
8.0.140.0030.00516.84
8.0.130.0050.00013.29
8.0.120.0020.00516.87
8.0.110.0000.00716.88
8.0.100.0050.00216.77
8.0.90.0040.00416.78
8.0.80.0100.00616.96
8.0.70.0080.00016.80
8.0.60.0000.00816.89
8.0.50.0000.00816.85
8.0.30.0110.00816.91
8.0.20.0120.00617.40
8.0.10.0000.00717.02
8.0.00.0050.01516.83
7.4.330.0020.00215.55
7.4.320.0060.00016.42
7.4.300.0030.00516.59
7.4.290.0000.00816.58
7.4.280.0030.00616.41
7.4.270.0030.00316.64
7.4.260.0000.00716.49
7.4.250.0050.00316.56
7.4.240.0000.00716.54
7.4.230.0030.00316.68
7.4.220.0000.00716.42
7.4.210.0030.01416.57
7.4.200.0050.00316.42
7.4.160.0110.00616.54
7.4.140.0090.00917.86
7.4.130.0150.00316.59
7.4.120.0130.00716.50
7.4.110.0130.00316.66
7.4.100.0070.01116.56
7.4.90.0030.01516.50
7.4.80.0080.00619.39
7.4.70.0060.00916.59
7.4.60.0070.01016.45
7.4.50.0040.01116.55
7.4.40.0120.00916.41
7.4.00.0060.00914.67
7.3.330.0000.00513.25
7.3.320.0000.00713.25
7.3.310.0070.00016.26
7.3.300.0000.00716.34
7.3.290.0070.00016.26
7.3.280.0080.00616.37
7.3.260.0100.01016.50
7.3.240.0100.00616.35
7.3.230.0070.01016.46
7.3.210.0030.01416.25
7.3.200.0100.00616.58
7.3.190.0040.01416.55
7.3.180.0100.00716.70
7.3.170.0100.00716.59
7.3.160.0030.01416.49
7.3.10.0090.00616.37
7.3.00.0130.00716.21
7.2.330.0050.02016.82
7.2.320.0140.00816.82
7.2.310.0000.01616.58
7.2.300.0080.00816.77
7.2.290.0210.00316.66
7.2.130.0080.01116.39
7.2.120.0110.00816.25
7.2.110.0050.00916.83
7.2.100.0140.00516.90
7.2.90.0190.00516.54
7.2.80.0070.01016.48
7.2.70.0140.01116.70
7.2.60.0020.01316.58
7.2.50.0050.00916.70
7.2.40.0220.00817.34
7.2.30.0220.00517.51
7.2.20.0140.01017.33
7.2.10.0170.00917.23
7.2.00.0220.00917.64
7.1.250.0110.00415.30
7.1.200.0000.01315.81
7.1.160.0230.01216.82
7.1.150.0360.01216.96
7.1.140.0240.01017.01
7.1.130.0240.01116.80
7.1.120.0250.01216.67
7.1.110.0220.00915.96
7.1.100.0200.00916.19
7.1.90.0270.00815.98
7.1.80.0190.01216.13
7.1.70.0190.01115.45
7.1.60.0550.01433.03
7.1.50.0460.01933.14
7.1.40.0480.01632.49
7.1.30.0400.01432.59
7.1.20.0370.01332.63
7.1.10.0240.01414.66
7.1.00.0200.01214.85

preferences:
112.05 ms | 403 KiB | 5 Q