3v4l.org

run code in 300+ PHP versions simultaneously
<?php function valueSeparator(array $array) { $maxIterations = count($array); $counted = array_count_values($array); arsort($counted); $iteration = 0; $result = []; while (max($counted) > 1 && $iteration < $maxIterations) { $count = reset($counted); $value = key($counted); $result[] = $value; unset($counted[$value]); arsort($counted); if ($count > 1) { $counted = array_merge( array_splice($counted, 0, 1), [$value => $count - 1], $counted ); } ++$iteration; } array_push($result, ...array_keys($counted)); var_export($result); } $arrays = [ ['Retail', 'Retail', 'Food', 'Food', 'Retail'], ['Retail', 'Retail', 'Food', 'Charity', 'Entertainment', 'Entertainment', 'Transport', 'Cosmetics'], ['Food'], ['Retail', 'Retail', 'Food', 'Retail'], ['Retail', 'Retail', 'Retail', 'Food', 'Food', 'Food', 'Charity', 'Charity', 'Charity'], ['Charity', 'Entertainment', 'Retail', 'Retail' ,'Retail'] ]; foreach ($arrays as $array) { valueSeparator($array); echo "\n---\n"; }

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.3.70.0070.00716.58
8.3.60.0120.00318.43
8.3.50.0080.00817.95
8.3.40.0040.01118.59
8.3.30.0070.00718.82
8.3.20.0050.00324.18
8.3.10.0080.00024.66
8.3.00.0040.00426.16
8.2.190.0120.00318.46
8.2.180.0090.00625.92
8.2.170.0180.00418.94
8.2.160.0070.00722.96
8.2.150.0000.00725.66
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0080.00026.35
8.2.110.0060.00322.13
8.2.100.0070.00417.91
8.2.90.0000.00818.03
8.2.80.0080.00018.16
8.2.70.0040.00418.04
8.2.60.0090.00018.28
8.2.50.0030.00618.10
8.2.40.0060.00321.23
8.2.30.0040.00419.23
8.2.20.0040.00418.09
8.2.10.0050.00219.30
8.2.00.0000.00819.29
8.1.280.0110.00325.92
8.1.270.0130.00722.24
8.1.260.0070.00028.09
8.1.250.0060.00328.09
8.1.240.0090.00317.48
8.1.230.0120.00022.67
8.1.220.0000.00817.79
8.1.210.0040.00418.77
8.1.200.0030.00717.35
8.1.190.0040.00417.23
8.1.180.0060.00318.10
8.1.170.0040.00418.53
8.1.160.0090.00318.98
8.1.150.0050.00318.89
8.1.140.0030.00618.77
8.1.130.0040.00420.18
8.1.120.0040.00417.39
8.1.110.0030.00617.36
8.1.100.0030.00317.48
8.1.90.0030.00617.46
8.1.80.0060.00317.36
8.1.70.0040.00417.35
8.1.60.0040.00417.59
8.1.50.0040.00417.54
8.1.40.0040.00417.44
8.1.30.0030.00617.48
8.1.20.0000.00817.66
8.1.10.0000.00917.57
8.1.00.0040.00417.47
8.0.300.0000.00720.12
8.0.290.0080.00416.75
8.0.280.0040.00418.43
8.0.270.0030.00316.93
8.0.260.0030.00318.46
8.0.250.0030.00317.05
8.0.240.0040.00417.04
8.0.230.0000.00716.93
8.0.220.0000.00616.86
8.0.210.0000.00716.97
8.0.200.0060.00016.93
8.0.190.0090.00016.95
8.0.180.0040.00416.94
8.0.170.0040.00416.91
8.0.160.0040.00416.94
8.0.150.0070.00016.72
8.0.140.0040.00416.80
8.0.130.0050.00513.30
8.0.120.0040.00416.85
8.0.110.0000.00816.83
8.0.100.0040.00416.80
8.0.90.0040.00416.75
8.0.80.0050.01016.82
8.0.70.0000.00716.75
8.0.60.0080.00016.80
8.0.50.0040.00416.76
8.0.30.0070.01016.95
8.0.20.0090.00916.98
8.0.10.0000.00716.97
8.0.00.0130.01016.49
7.4.330.0040.00216.73
7.4.320.0060.00016.42
7.4.300.0030.00316.59
7.4.290.0000.00816.51
7.4.280.0000.00816.52
7.4.270.0030.00316.62
7.4.260.0030.00313.24
7.4.250.0050.00216.41
7.4.240.0000.00716.53
7.4.230.0070.00016.60
7.4.220.0020.00716.40
7.4.210.0070.00916.58
7.4.200.0030.00316.30
7.4.130.0110.00816.44
7.4.120.0140.01016.55
7.4.110.0090.00916.54
7.4.100.0100.00616.50
7.4.90.0110.00816.51
7.4.80.0150.00916.48
7.4.70.0100.00916.65
7.4.60.0110.00616.52
7.4.50.0090.00916.59
7.4.40.0190.00616.50
7.4.30.0110.00716.61
7.4.20.0100.01016.34
7.4.10.0070.01016.25
7.4.00.0100.00716.49
7.3.330.0020.00516.32
7.3.320.0000.00513.33
7.3.310.0000.00716.18
7.3.300.0000.00716.38
7.3.290.0110.00416.34
7.3.260.0150.00416.27
7.3.230.0030.01316.61
7.3.210.0070.01416.48
7.3.200.0040.01916.55
7.3.190.0110.00716.41
7.3.180.0060.01116.27
7.3.170.0120.00916.43
7.3.160.0120.00916.48
7.3.150.0040.01516.16
7.3.140.0070.01016.64
7.3.130.0070.01416.32
7.3.120.0140.00516.54
7.3.110.0150.00316.65
7.3.100.0140.00316.33
7.3.90.0120.00616.58
7.3.80.0100.00716.50
7.3.70.0090.00916.44
7.3.60.0070.01116.43
7.3.50.0160.00416.52
7.3.40.0090.00916.36
7.3.30.0090.00916.38
7.3.20.0110.00816.34
7.3.10.0150.00716.39
7.3.00.0090.01416.55
7.2.330.0090.00916.73
7.2.320.0120.01216.63
7.2.310.0110.00716.86
7.2.300.0150.00616.62
7.2.290.0060.01616.53
7.2.280.0060.01316.70
7.2.270.0060.01216.75
7.2.260.0090.01216.58
7.2.250.0110.00716.71
7.2.240.0140.00416.70
7.2.230.0130.00716.74
7.2.220.0090.00916.65
7.2.210.0150.00616.68
7.2.200.0100.00916.73
7.2.190.0090.01216.66
7.2.180.0140.00716.49
7.2.170.0100.00916.68
7.2.160.0150.00416.50
7.2.150.0030.01716.76
7.2.140.0260.01316.72
7.2.130.0200.00016.63
7.2.120.0060.01216.73
7.2.110.0090.01316.75
7.2.100.0030.01616.81
7.2.90.0100.01016.85
7.2.80.0090.00916.48
7.2.70.0150.00416.60
7.2.60.0150.00416.51
7.2.50.0110.00716.56
7.2.40.0120.00616.70
7.2.30.0200.00816.68
7.2.20.0100.00716.62
7.2.10.0090.01216.63
7.2.00.0060.01516.56

preferences:
73.25 ms | 401 KiB | 5 Q