3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [ [ 'user_id' => 120, 'username' => 'test1', 'count' => 2 ], [ 'user_id' => 120, 'username' => 'test1', 'count' => 3 ], [ 'user_id' => 110, 'username' => 'test2', 'count' => 2 ] ]; /** loop through "$arr" and sum the "count" values based on the "user_id" */ $result = array_reduce($arr, function ($a, $c) { /** index the resulting array by the "user_id" value which allows for instant lookup in case of duplicate "user_id" value */ $a[$c['user_id']] = [ 'user_id' => $c['user_id'], 'username' => $c['username'], /** sum the "count" values * the first iteration will have an empty array * so we should check for existance before getting the value in order to prevent bugs */ 'count' => ($a[$c['user_id']]['count'] ?? 0) + $c['count'] ]; return $a; }, []); var_export($result);

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.60.0080.01016.75
8.5.50.0120.00616.67
8.5.30.0090.00917.60
8.5.20.0100.00919.34
8.5.10.0070.00921.85
8.5.00.0130.00821.89
8.4.210.0120.01019.63
8.4.180.0130.00921.95
8.4.170.0100.01220.32
8.4.160.0120.01022.37
8.4.150.0090.00416.90
8.4.140.0110.01117.48
8.4.130.0060.00317.51
8.4.120.0130.00720.56
8.4.110.0100.00922.68
8.4.100.0130.00717.59
8.4.90.0090.01218.68
8.4.80.0040.00417.95
8.4.70.0040.00517.67
8.4.60.0110.00918.84
8.4.50.0120.00818.03
8.4.40.0080.01119.63
8.4.30.0080.00019.04
8.4.20.0120.00917.92
8.4.10.0090.00022.16
8.3.300.0100.01020.80
8.3.290.0090.01020.88
8.3.280.0050.00418.49
8.3.270.0130.01216.74
8.3.260.0110.00816.60
8.3.250.0110.00818.83
8.3.240.0110.00716.46
8.3.230.0110.00716.45
8.3.220.0110.00817.17
8.3.210.0040.00416.74
8.3.200.0050.00316.54
8.3.190.0070.01016.61
8.3.180.0140.00516.86
8.3.170.0110.00717.45
8.3.160.0130.00716.61
8.3.150.0000.00817.16
8.3.140.0090.00916.68
8.3.130.0120.00618.28
8.3.120.0000.00820.77
8.3.110.0080.00018.34
8.3.100.0050.00316.54
8.3.90.0040.00426.77
8.3.80.0100.00016.63
8.3.70.0140.00416.58
8.3.60.0140.00418.31
8.3.50.0070.00720.16
8.3.40.0110.00420.46
8.3.30.0070.00718.84
8.3.20.0000.00724.18
8.3.10.0080.00024.66
8.3.00.0080.00026.16
8.2.300.0130.00722.13
8.2.290.0110.00820.54
8.2.280.0120.00818.49
8.2.270.0110.00716.63
8.2.260.0110.00718.70
8.2.250.0000.00817.38
8.2.240.0060.00319.30
8.2.230.0040.00720.94
8.2.220.0030.00524.06
8.2.210.0080.00026.77
8.2.200.0030.00616.75
8.2.190.0040.01116.58
8.2.180.0090.00625.92
8.2.170.0080.00622.96
8.2.160.0100.00322.96
8.2.150.0040.00425.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0070.00026.16
8.2.110.0030.00720.58
8.2.100.0030.00720.35
8.1.340.0120.01119.74
8.1.330.0090.00921.89
8.1.320.0110.00816.18
8.1.310.0070.01118.50
8.1.300.0190.00316.36
8.1.290.0040.00430.84
8.1.280.0090.00925.92
8.1.270.0000.00824.66
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00318.56
8.1.230.0030.00718.70
7.4.300.0030.00316.59

preferences:
49.33 ms | 874 KiB | 5 Q