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'); foreach($items as $key => $value) { echo '<li><strong>' . $key . '</strong></li>'; foreach($value as $row) { echo '<li><a href="/category/'.$row['category'].'">'.$row['category'].'</a></li>'; } }

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.0140.00717.49
8.4.130.0150.00617.77
8.4.120.0110.01020.77
8.4.110.0050.00319.16
8.4.100.0050.00617.93
8.4.90.0120.00820.66
8.4.80.0120.00819.55
8.4.70.0120.00918.05
8.4.60.0100.00918.85
8.4.50.0110.00718.96
8.4.40.0030.01619.24
8.4.30.0130.00719.25
8.4.20.0070.01317.77
8.4.10.0070.00317.79
8.3.270.0120.00716.55
8.3.260.0090.00316.57
8.3.250.0090.00819.15
8.3.240.0040.00416.56
8.3.230.0130.00816.71
8.3.220.0130.00518.79
8.3.210.0120.01018.55
8.3.200.0050.00416.54
8.3.190.0160.00317.14
8.3.180.0070.01216.63
8.3.170.0070.01020.79
8.3.160.0060.00320.20
8.3.150.0120.00616.82
8.3.140.0080.00016.74
8.3.130.0070.00318.50
8.3.120.0000.00920.83
8.3.110.0040.00420.94
8.3.100.0060.00324.06
8.3.90.0060.00326.77
8.3.80.0090.00018.43
8.3.70.0070.00716.88
8.3.60.0140.00718.19
8.3.50.0100.01222.06
8.3.40.0120.00318.77
8.3.30.0110.00418.82
8.3.20.0040.00420.34
8.3.10.0030.00620.52
8.3.00.0040.00420.93
8.2.290.0130.00618.95
8.2.280.0030.00418.78
8.2.270.0140.00719.06
8.2.260.0110.00716.78
8.2.250.0040.00418.17
8.2.240.0000.00817.16
8.2.230.0090.00022.58
8.2.220.0080.00037.54
8.2.210.0040.00426.77
8.2.200.0040.00418.64
8.2.190.0110.00416.63
8.2.180.0120.00318.41
8.2.170.0070.00722.96
8.2.160.0140.00019.41
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0040.00421.18
8.2.110.0060.00321.89
8.2.100.0000.01217.75
8.2.90.0080.00018.03
8.2.80.0060.00319.15
8.2.70.0040.00417.63
8.2.60.0060.00317.63
8.2.50.0040.00418.09
8.2.40.0000.00720.60
8.2.30.0030.00719.56
8.2.20.0040.00417.86
8.2.10.0000.00718.16
8.2.00.0070.00018.15
8.1.330.0070.01218.40
8.1.320.0090.00716.40
8.1.310.0090.00618.70
8.1.300.0080.00020.04
8.1.290.0030.00630.84
8.1.280.0110.00425.92
8.1.270.0080.00024.02
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0040.00423.88
8.1.230.0000.01120.97
8.1.220.0050.00317.74
8.1.210.0030.00618.77
8.1.200.0060.00317.25
8.1.190.0080.00017.23
8.1.180.0040.00418.10
8.1.170.0080.00018.72
8.1.160.0000.00720.80
8.1.150.0050.00319.02
8.1.140.0000.00919.64
8.1.130.0030.00317.74
8.1.120.0000.00717.36
8.1.110.0070.00017.43
8.1.100.0000.00817.45
8.1.90.0040.00417.50
8.1.80.0000.00717.43
8.1.70.0070.00017.38
8.1.60.0000.00717.68
8.1.50.0000.00817.57
8.1.40.0030.00517.52
8.1.30.0000.00817.73
8.1.20.0000.00717.63
8.1.10.0050.00317.65
8.1.00.0040.00417.46
8.0.300.0040.00420.06
8.0.290.0080.00016.75
8.0.280.0000.00718.40
8.0.270.0000.00716.86
8.0.260.0040.00417.22
8.0.250.0030.00316.90
8.0.240.0050.00316.89
8.0.230.0000.00816.96
8.0.220.0000.00716.85
8.0.210.0030.00316.91
8.0.200.0000.00816.95
8.0.190.0000.00816.94
8.0.180.0030.00316.97
8.0.170.0000.00916.98
8.0.160.0040.00416.82
8.0.150.0040.00416.87
8.0.140.0080.00016.84
8.0.130.0030.00313.32
8.0.120.0000.00916.91
8.0.110.0070.00016.90
8.0.100.0050.00216.83
8.0.90.0080.00016.95
8.0.80.0080.00816.81
8.0.70.0040.00416.86
8.0.60.0000.00716.93
8.0.50.0040.00416.88
8.0.30.0100.00817.02
8.0.20.0130.00517.40
8.0.10.0060.00317.04
8.0.00.0060.01216.77
7.4.330.0060.00015.08
7.4.320.0060.00016.45
7.4.300.0030.00316.53
7.4.290.0030.00616.47
7.4.280.0080.00316.59
7.4.270.0030.00316.60
7.4.260.0040.00416.55
7.4.250.0030.00516.52
7.4.240.0030.00316.55
7.4.230.0040.00416.54
7.4.220.0080.00816.54
7.4.210.0070.00716.55
7.4.200.0030.00316.43
7.4.160.0030.01316.55
7.4.150.0100.00717.40
7.4.140.0140.00817.86
7.4.130.0070.01116.58
7.4.120.0060.01316.62
7.4.110.0100.00716.58
7.4.100.0110.00716.62
7.4.90.0060.01016.48
7.4.80.0090.00619.39
7.4.70.0080.00816.67
7.4.60.0060.01316.49
7.4.50.0100.00316.53
7.4.40.0040.01416.56
7.4.30.0130.00316.56
7.4.00.0050.01214.82
7.3.330.0050.00013.37
7.3.320.0020.00213.36
7.3.310.0040.00416.39
7.3.300.0030.00316.38
7.3.290.0070.00016.24
7.3.280.0090.01116.37
7.3.270.0240.00017.40
7.3.260.0090.00916.30
7.3.250.0090.01116.46
7.3.240.0110.00816.55
7.3.230.0090.00916.45
7.3.210.0100.01316.43
7.3.200.0110.00619.39
7.3.190.0110.00616.56
7.3.180.0100.00716.46
7.3.170.0110.00616.66
7.3.160.0080.00816.38
7.3.120.0070.01114.79
7.3.110.0090.00914.63
7.3.100.0080.00714.96
7.3.90.0060.00714.82
7.3.80.0040.01014.86
7.3.70.0020.00814.81
7.3.60.0030.01114.72
7.3.50.0090.00614.92
7.3.40.0040.00814.87
7.3.30.0080.00314.57
7.3.20.0020.01116.54
7.3.10.0010.01116.55
7.3.00.0040.01016.62
7.2.330.0030.01516.44
7.2.320.0100.00416.77
7.2.310.0070.01016.68
7.2.300.0090.00916.68
7.2.290.0030.01316.45
7.2.250.0100.00714.80
7.2.240.0060.01315.03
7.2.230.0090.00515.08
7.2.220.0030.01215.11
7.2.210.0000.01114.87
7.2.200.0070.01115.18
7.2.190.0100.00315.05
7.2.180.0030.01114.77
7.2.170.0050.00714.96
7.2.160.0090.00615.00
7.2.150.0110.00017.01
7.2.140.0060.00317.08
7.2.130.0070.00717.03
7.2.120.0030.01016.80
7.2.110.0110.00416.73
7.2.100.0030.01316.73
7.2.90.0030.00716.89
7.2.80.0090.00317.04
7.2.70.0130.00317.09
7.2.60.0090.00516.98
7.2.50.0090.00616.79
7.2.40.0060.00916.91
7.2.30.0140.00317.12
7.2.20.0130.00017.01
7.2.10.0030.01317.02
7.2.00.0070.00716.72
7.1.330.0070.00915.75
7.1.320.0080.00415.90
7.1.310.0090.00515.84
7.1.300.0080.00615.80
7.1.290.0020.01415.81
7.1.280.0070.00515.82
7.1.270.0090.00215.66
7.1.260.0050.00815.69
7.1.250.0030.01015.63
7.1.200.0040.00715.70
7.1.110.0000.02118.28
7.1.100.0100.00318.03
7.1.90.0040.01118.37
7.1.80.0040.01118.00
7.1.70.0030.01216.93
7.1.60.0050.02027.00
7.1.50.0130.01334.56
7.1.40.0170.01334.39
7.1.30.0190.00634.21
7.1.20.0260.01034.73
7.1.10.0120.00316.63
7.1.00.0070.04019.46
7.0.250.0090.00917.58
7.0.240.0100.00317.89
7.0.230.0050.00917.69
7.0.220.0070.00617.71
7.0.210.0000.01216.66
7.0.200.0860.00515.81
7.0.190.0060.00616.59
7.0.180.0090.00616.17
7.0.170.0080.00416.16
7.0.160.0040.00816.18
7.0.150.0060.00616.37
7.0.140.0060.00916.35
7.0.130.0040.01416.50
7.0.120.0000.01416.47
7.0.110.0030.01016.25
7.0.100.0030.03218.33
7.0.90.0150.02318.17
7.0.80.0090.02318.18
7.0.70.0030.02718.13
7.0.60.0100.03118.12
7.0.50.0060.02218.33
7.0.40.0090.01818.38
7.0.30.0050.02618.31
7.0.20.0020.02418.35
7.0.10.0090.03718.18
7.0.00.0090.03618.29
5.6.300.0100.05520.80
5.6.290.0030.05820.63
5.6.280.0080.07120.92
5.6.270.0140.05220.95
5.6.260.0030.06120.97
5.6.250.0070.04820.80
5.6.240.0050.07220.81
5.6.230.0080.04820.79
5.6.220.0070.06020.73
5.6.210.0080.06320.83
5.6.200.0070.06820.94
5.6.190.0100.06120.84
5.6.180.0080.04420.99
5.6.170.0130.04020.93
5.6.160.0070.06420.90
5.6.150.0080.06520.91
5.6.140.0060.05521.03
5.6.130.0080.04720.88
5.6.120.0050.05520.97
5.6.110.0110.04220.97
5.6.100.0100.04721.05
5.6.90.0070.04721.07
5.6.80.0110.04120.37
5.6.70.0030.04920.27
5.6.60.0030.04520.27
5.6.50.0170.03620.32
5.6.40.0070.04320.33
5.6.30.0030.05020.26
5.6.20.0110.03920.31
5.6.10.0030.04820.39
5.6.00.0060.05220.34
5.5.380.0050.06719.02
5.5.370.0150.04218.94
5.5.360.0100.06318.89
5.5.350.0130.06818.99
5.5.340.0070.07319.34
5.5.330.0120.06219.42
5.5.320.0120.04919.50
5.5.310.0120.06619.46
5.5.300.0030.07419.35
5.5.290.0050.04719.25
5.5.280.0100.04619.45
5.5.270.0100.04819.46
5.5.260.0120.04519.29
5.5.250.0080.04519.25
5.5.240.0020.05118.79
5.5.230.0080.04318.79
5.5.220.0020.04718.69
5.5.210.0060.04118.73
5.5.200.0080.03918.78
5.5.190.0030.04518.72
5.5.180.0100.04018.79
5.5.160.0070.04118.86
5.5.150.0070.05418.83
5.5.140.0070.05418.84
5.5.130.0020.04518.61
5.5.120.0080.04418.65
5.5.110.0070.04218.71
5.5.100.0070.06018.74
5.5.90.0020.04918.66
5.5.80.0050.05418.64
5.5.70.0080.05218.67
5.5.60.0120.04818.72
5.5.50.0130.04118.65
5.5.40.0100.04918.72
5.5.30.0100.05118.62
5.5.20.0090.04318.52
5.5.10.0070.05518.65
5.5.00.0080.04418.67

preferences:
40.06 ms | 403 KiB | 5 Q