3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_group_by($arr, $key) { if (!is_array($arr)) { trigger_error('array_group_by(): The first argument should be an array', E_USER_ERROR); } if (!is_string($key) && !is_int($key) && !is_float($key)) { trigger_error('array_group_by(): The key should be a string or an integer', E_USER_ERROR); } // Load the new array, splitting by the target key $grouped = []; foreach ($arr as $value) { $grouped[$value[$key]][] = $value; } // Recursively build a nested grouping if more parameters are supplied // Each grouped array value is grouped according to the next sequential key if (func_num_args() > 2) { $args = func_get_args(); foreach ($grouped as $key => $value) { $parms = array_merge([$value], array_slice($args, 2, func_num_args())); $grouped[$key] = call_user_func_array('array_group_by', $parms); } } return $grouped; } $rows = [ [ 'name' => 'This is apple', 'category' => 'apple', 'first_category' => 'fruit' ], [ 'name' => 'This is orange', 'category' => 'orange', 'first_category' => 'fruit' ], [ 'name' => 'This is pear', 'category' => 'pear', 'first_category' => 'fruit' ], [ 'name' => 'This is carrot', 'category' => 'carrot', 'first_category' => 'vegetable' ], [ 'name' => 'This is tomatoe', 'category' => 'tomatoe', 'first_category' => 'vegetable' ] ]; $items = array_group_by($rows, 'first_category'); var_dump($items);

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.140.0100.01117.58
8.4.130.0170.00618.88
8.4.120.0140.00817.54
8.4.110.0120.01017.55
8.4.100.0110.01119.42
8.4.90.0080.01220.47
8.4.80.0130.00817.87
8.4.70.0010.00817.96
8.4.60.0040.00519.27
8.4.50.0080.01022.21
8.4.40.0100.01019.64
8.4.30.0100.00617.69
8.4.20.0170.00417.73
8.4.10.0000.01017.76
8.3.270.0160.00416.81
8.3.260.0090.01116.72
8.3.250.0090.00816.72
8.3.240.0080.01016.46
8.3.230.0130.00816.55
8.3.220.0140.00519.23
8.3.210.0150.00716.48
8.3.200.0110.00816.40
8.3.190.0100.00916.53
8.3.180.0050.00316.69
8.3.170.0040.00418.95
8.3.160.0110.00318.31
8.3.150.0150.00420.48
8.3.140.0000.00916.59
8.3.130.0030.00616.67
8.3.120.0030.00620.74
8.3.110.0080.00816.75
8.3.100.0060.00320.28
8.3.90.0080.00026.77
8.3.80.0030.00619.36
8.3.70.0040.01116.63
8.3.60.0100.01318.56
8.3.50.0130.00722.12
8.3.40.0090.00618.66
8.3.30.0110.00318.81
8.3.20.0040.00420.38
8.3.10.0000.00818.94
8.3.00.0000.00820.84
8.2.290.0120.00716.67
8.2.280.0130.00618.30
8.2.270.0090.00917.27
8.2.260.0060.01219.06
8.2.250.0080.00017.19
8.2.240.0090.00019.07
8.2.230.0000.00820.94
8.2.220.0060.00324.06
8.2.210.0030.00626.77
8.2.200.0040.00718.88
8.2.190.0090.00616.63
8.2.180.0130.00318.29
8.2.170.0120.00419.13
8.2.160.0140.00022.96
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0080.00019.36
8.2.120.0040.00426.35
8.2.110.0110.00021.11
8.2.100.0040.00817.86
8.2.90.0110.00019.76
8.2.80.0040.00419.23
8.2.70.0040.00417.63
8.2.60.0050.00318.05
8.2.50.0030.00618.07
8.2.40.0040.00418.26
8.2.30.0070.00018.13
8.2.20.0050.00317.70
8.2.10.0000.00718.04
8.2.00.0020.00618.16
8.1.330.0100.01016.07
8.1.320.0130.00716.39
8.1.310.0070.01116.95
8.1.300.0070.01118.51
8.1.290.0030.00730.84
8.1.280.0080.00825.92
8.1.270.0000.00823.84
8.1.260.0030.00528.09
8.1.250.0050.00328.09
8.1.240.0050.00521.29
8.1.230.0110.00017.52
8.1.220.0050.00317.78
8.1.210.0040.00418.77
8.1.200.0100.00017.38
8.1.190.0000.00917.35
8.1.180.0060.00318.10
8.1.170.0060.00318.88
8.1.160.0040.00418.90
8.1.150.0000.00718.92
8.1.140.0030.00519.62
8.1.130.0000.00717.77
8.1.120.0000.00717.57
8.1.110.0020.00517.49
8.1.100.0000.00717.56
8.1.90.0040.00417.38
8.1.80.0040.00417.49
8.1.70.0020.00517.50
8.1.60.0000.00817.57
8.1.50.0040.00417.55
8.1.40.0080.00017.58
8.1.30.0050.00317.71
8.1.20.0050.00317.69
8.1.10.0050.00317.58
8.1.00.0000.00717.55
8.0.300.0000.00718.77
8.0.290.0000.00716.75
8.0.280.0030.00318.35
8.0.270.0070.00016.73
8.0.260.0050.00318.52
8.0.250.0030.00317.00
8.0.240.0060.00316.88
8.0.230.0030.00316.89
8.0.220.0070.00016.98
8.0.210.0000.00716.77
8.0.200.0040.00416.93
8.0.190.0040.00417.00
8.0.180.0060.00316.84
8.0.170.0000.00816.84
8.0.160.0040.00416.83
8.0.150.0070.00016.82
8.0.140.0000.00816.72
8.0.130.0030.00313.34
8.0.120.0000.00816.84
8.0.110.0000.00816.90
8.0.100.0030.00416.94
8.0.90.0040.00416.88
8.0.80.0070.01716.91
8.0.70.0040.00416.82
8.0.60.0040.00416.90
8.0.50.0030.00616.95
8.0.30.0080.01116.98
8.0.20.0100.01117.40
8.0.10.0050.00316.85
8.0.00.0140.00716.93
7.4.330.0000.00515.08
7.4.320.0060.00016.53
7.4.300.0030.00316.60
7.4.290.0040.00416.53
7.4.280.0000.01016.53
7.4.270.0070.00016.63
7.4.260.0000.00716.66
7.4.250.0090.00016.43
7.4.240.0000.00716.60
7.4.230.0050.00216.62
7.4.220.0100.01116.52
7.4.210.0070.01416.43
7.4.200.0000.00716.66
7.4.160.0080.00816.43
7.4.150.0100.00817.40
7.4.140.0090.01117.86
7.4.130.0120.00916.55
7.4.120.0110.00816.42
7.4.110.0090.00916.41
7.4.100.0120.01516.55
7.4.90.0170.00316.43
7.4.80.0090.00919.39
7.4.70.0130.00516.41
7.4.60.0000.01816.60
7.4.50.0030.00716.49
7.4.40.0100.01016.63
7.4.30.0030.01316.44
7.4.00.0070.01014.98
7.3.330.0000.00613.23
7.3.320.0000.00613.21
7.3.310.0080.00016.46
7.3.300.0000.00716.42
7.3.290.0100.00616.37
7.3.280.0120.00716.38
7.3.270.0110.00517.40
7.3.260.0160.00616.59
7.3.250.0070.01216.43
7.3.240.0100.01216.39
7.3.230.0120.01216.66
7.3.210.0060.01616.57
7.3.200.0100.00619.39
7.3.190.0060.01016.46
7.3.180.0050.01316.34
7.3.170.0110.00616.59
7.3.160.0100.00716.49
7.2.330.0150.00916.69
7.2.320.0190.00416.48
7.2.310.0110.00816.55
7.2.300.0090.00916.75
7.2.290.0080.00816.84
7.2.60.0240.00316.87
7.2.50.0070.00417.07
7.1.200.0000.01415.77
7.1.100.0030.00718.09
7.1.70.0000.01717.22
7.1.60.0040.02119.19
7.1.00.0030.07722.45
7.0.200.0080.00016.81
7.0.60.0300.07719.99
7.0.50.0100.06717.88
7.0.40.0070.07020.09
7.0.30.0270.04320.21
7.0.20.0270.08320.09
7.0.10.0170.04720.24
7.0.00.0070.04320.23
5.6.280.0070.06721.05
5.6.210.0100.03320.73
5.6.200.0030.04018.16
5.6.190.0170.07720.58
5.6.180.0230.08020.55
5.6.170.0300.08020.57
5.6.160.0070.06020.54
5.6.150.0130.07718.19
5.6.140.0130.07018.16
5.6.130.0100.07718.24
5.6.120.0100.08321.05
5.6.110.0030.04321.00
5.6.100.0070.08721.09
5.6.90.0070.07021.12
5.6.80.0130.04020.40
5.5.350.4230.04020.38
5.5.340.0100.07318.05
5.5.330.0070.08320.40
5.5.320.0370.04020.32
5.5.310.0270.06320.30
5.5.300.0070.05317.94
5.5.290.0070.08018.04
5.5.280.0130.04020.79
5.5.270.0130.07720.78
5.5.260.0100.08020.80
5.5.250.0100.08020.46
5.5.240.0500.05320.27

preferences:
31.75 ms | 403 KiB | 5 Q