3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sampleArray = [ ["id" => 0.1, "marks" => 2], ["id" => 0.2, "marks" => 4], ["id" => 0.3, "marks" => 1], ["id" => 1.1, "marks" => 6], ["id" => 1.2, "marks" => 0], ["id" => 1.8, "marks" => 8], ["id" => 2.1, "marks" => 7], ["id" => 2.2, "marks" => 12], ]; $result = []; foreach ($sampleArray as $row) { if ($result && !isset($result[$row['id']])) { // $result is not empty and current id is not yet in output array $lastKey = array_key_last($result); echo "Sum of ID $lastKey is {$result[$lastKey]}<br><br>"; } echo "id: {$row['id']}, marks: {$row['marks']}<br>"; $result[$row['id']] = ($result[$row['id']] ?? 0) + $row['marks']; } if ($result) { $lastKey = array_key_last($result); echo "Sum of ID $lastKey is {$result[$lastKey]}"; }

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.0040.00517.80
8.4.120.0100.01120.61
8.4.110.0130.00620.55
8.4.100.0070.00318.78
8.4.90.0130.00820.76
8.4.80.0100.01218.57
8.4.70.0070.00918.89
8.4.60.0120.00820.57
8.4.50.0120.00824.02
8.4.40.0130.00720.56
8.4.30.0030.00620.57
8.4.20.0070.01420.43
8.4.10.0090.00619.70
8.3.260.0140.00916.75
8.3.250.0050.00418.96
8.3.240.0150.00516.95
8.3.230.0100.00816.62
8.3.220.0080.00719.01
8.3.210.0100.00816.93
8.3.200.0040.00516.94
8.3.190.0110.01017.34
8.3.180.0070.00516.78
8.3.170.0110.00716.95
8.3.160.0130.00620.09
8.3.150.0000.00818.40
8.3.140.0000.00817.11
8.3.130.0030.00618.35
8.3.120.0130.00618.86
8.3.110.0080.00820.94
8.3.100.0060.00324.06
8.3.90.0040.00426.77
8.3.80.0030.00716.88
8.3.70.0100.00616.63
8.3.60.0070.00718.17
8.3.50.0080.00816.42
8.3.40.0110.01118.98
8.3.30.0130.00318.76
8.3.20.0080.00024.18
8.3.10.0060.00324.66
8.3.00.0030.00626.16
8.2.290.0090.00920.32
8.2.280.0110.00920.19
8.2.270.0110.00417.45
8.2.260.0090.00918.14
8.2.250.0090.00316.93
8.2.240.0040.00418.79
8.2.230.0030.00622.58
8.2.220.0030.00637.54
8.2.210.0050.00326.77
8.2.200.0060.00316.50
8.2.190.0030.01417.00
8.2.180.0140.00425.92
8.2.170.0040.01122.96
8.2.160.0070.00722.96
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0000.00821.04
8.2.110.0030.00620.96
8.2.100.0080.00417.91
8.2.90.0080.00018.34
8.2.80.0060.00317.97
8.2.70.0000.00917.50
8.2.60.0040.00418.04
8.2.50.0000.00818.07
8.2.40.0030.00519.81
8.2.30.0040.00418.01
8.2.20.0050.00218.11
8.2.10.0070.00019.38
8.2.00.0020.00519.30
8.1.330.0120.00621.94
8.1.320.0100.01017.78
8.1.310.0140.00318.51
8.1.300.0090.00617.62
8.1.290.0040.01118.88
8.1.280.0090.00925.92
8.1.270.0120.00423.72
8.1.260.0060.00326.35
8.1.250.0070.00028.09
8.1.240.0100.00722.25
8.1.230.0090.00320.79
8.1.220.0090.00017.76
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0000.00817.35
8.1.180.0040.00418.10
8.1.170.0040.00418.41
8.1.160.0050.00218.75
8.1.150.0030.00618.89
8.1.140.0060.00518.79
8.1.130.0000.00720.19
8.1.120.0070.00017.44
8.1.110.0040.00417.35
8.1.100.0090.00017.46
8.1.90.0060.00317.45
8.1.80.0030.00317.45
8.1.70.0070.00017.43
8.1.60.0000.00817.63
8.1.50.0050.00317.53
8.1.40.0040.00417.55
8.1.30.0080.00017.70
8.1.20.0030.00617.55
8.1.10.0040.00717.51
8.1.00.0090.00317.39
8.0.300.0070.00020.08
8.0.290.0050.00316.75
8.0.280.0020.00518.36
8.0.270.0000.00718.02
8.0.260.0000.00618.53
8.0.250.0030.00616.84
8.0.240.0050.00316.93
8.0.230.0000.00716.92
8.0.220.0000.00716.86
8.0.210.0000.00816.79
8.0.200.0000.00716.97
8.0.190.0000.00716.87
8.0.180.0000.00816.89
8.0.170.0040.00416.85
8.0.160.0040.00416.91
8.0.150.0000.00716.86
8.0.140.0090.00016.83
8.0.130.0050.00013.31
8.0.120.0040.00416.88
8.0.110.0050.00316.79
8.0.100.0000.00716.89
8.0.90.0000.00816.84
8.0.80.0120.02416.87
8.0.70.0240.01016.93
8.0.60.0280.00816.78
8.0.50.0610.00616.82
8.0.30.0270.01116.83
8.0.20.0190.01116.98
8.0.10.0120.02416.94
8.0.00.0250.00917.02
7.4.330.0020.00215.55
7.4.320.0030.00316.46
7.4.300.0000.00716.43
7.4.290.0000.00816.53
7.4.280.0000.00716.59
7.4.270.0030.00316.50
7.4.260.0070.00013.33
7.4.250.0000.00716.55
7.4.240.0000.00716.42
7.4.230.0040.00416.48
7.4.220.0160.00816.63
7.4.210.0280.00616.63
7.4.200.0230.00916.54
7.4.190.0210.00716.52
7.4.180.0240.00716.60
7.4.160.0260.00616.57
7.4.150.0240.00616.45
7.4.140.0200.01016.47
7.4.130.0220.00916.50
7.4.120.0190.01416.42
7.4.110.0290.01016.48
7.4.100.0180.01316.60
7.4.90.0210.01316.57
7.4.80.0310.01016.57
7.4.70.0230.00716.33
7.4.60.0220.01416.53
7.4.50.0200.01816.51
7.4.40.0160.01416.32
7.4.30.0220.00816.29
7.4.20.0150.01516.44
7.4.10.0300.00416.36
7.4.00.0190.01316.51
7.3.330.0090.00016.37
7.3.320.0050.00013.06
7.3.310.0030.00316.47
7.3.300.0000.00716.28
7.3.290.0390.01316.32
7.3.280.0280.00516.27
7.3.270.0250.01416.29
7.3.260.0220.00916.31
7.3.250.0250.01216.28
7.3.240.0260.00316.43
7.3.230.0270.00916.28
7.3.220.0150.01816.29
7.3.210.0240.00516.40
7.3.200.0250.01116.36
7.3.190.0070.02216.15
7.3.180.0200.01016.28
7.3.170.0190.00916.28
7.3.160.0230.01016.31
7.3.150.0320.00616.20
7.3.140.0190.01316.36
7.3.130.0180.01316.29
7.3.120.0240.00316.30
7.3.110.0250.00616.18
7.3.100.0330.00816.16
7.3.90.0280.00316.55
7.3.80.0240.01016.26
7.3.70.0180.01416.32
7.3.60.0170.01416.46
7.3.50.0200.00916.42
7.3.40.0250.00416.47
7.3.30.0190.01316.48
7.3.20.0210.00916.40
7.3.10.0180.01316.39
7.3.00.0250.00716.28

preferences:
28.05 ms | 403 KiB | 5 Q