3v4l.org

run code in 300+ PHP versions simultaneously
<?php $names = [ 'ab1 ab2', // becomes ba1 ba2 'qwerty uçop', // becomes ytrewq poçu 'q1werty% uio*pl', // becomes y1trewq% lpo*iu 'Привет, мир!', // becomes тевирП, рим! 'Hello, dear @user_non-name, congrats100 points*@!', // olleH, raed @eman_non-resu, stragnoc100 stniop*@! 'a' ]; function swapLetterPositions($string): string { $result = []; foreach (explode(' ', $string) as $index => $word) { $result[$index] = ''; $count = preg_match_all('/(\pL)|(.)/u', $word, $m, PREG_SET_ORDER); for ($i = 0, $j = $count; $i < $count; ++$i) { if (!$m[$i][1]) { // immovable $result[$index] .= $m[$i][2]; // append to string } else { // movable from front while (--$j >= 0) { if ($m[$j][1]) { // movable from back $result[$index] .= $m[$j][1]; // append to string break; } } } } } return implode(' ', $result); } foreach ($names as $name) { echo "\"$name\" => \"" . swapLetterPositions($name) . "\"\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.5.00.0130.00820.15
8.4.150.0010.00114.05
8.4.140.0140.00818.06
8.4.130.0110.01017.80
8.4.120.0100.01020.60
8.4.110.0080.00622.36
8.4.100.0140.00818.14
8.4.90.0150.00518.58
8.4.80.0050.00419.97
8.4.70.0090.01117.97
8.4.60.0140.00718.63
8.4.50.0070.00518.13
8.4.40.0130.00717.81
8.4.30.0120.00020.45
8.4.20.0140.00718.12
8.4.10.0030.00619.78
8.3.280.0120.00918.54
8.3.270.0120.01016.82
8.3.260.0080.01117.12
8.3.250.0120.00718.81
8.3.240.0050.00416.76
8.3.230.0080.01316.75
8.3.220.0100.00917.31
8.3.210.0120.00616.91
8.3.200.0050.00416.98
8.3.190.0110.00717.22
8.3.180.0080.01020.73
8.3.170.0150.00319.16
8.3.160.0090.00918.62
8.3.150.0110.00720.71
8.3.140.0040.00416.84
8.3.130.0080.00018.72
8.3.120.0040.00419.06
8.3.110.0060.00320.94
8.3.100.0110.00724.06
8.3.90.0050.00326.77
8.3.80.0000.00916.75
8.3.70.0080.00818.68
8.3.60.0160.00016.88
8.3.50.0180.00418.30
8.3.40.0160.00320.29
8.3.30.0120.00818.89
8.3.20.0050.00324.18
8.3.10.0080.00024.66
8.3.00.0040.00426.16
8.2.290.0090.00920.21
8.2.280.0090.01220.46
8.2.270.0050.00517.49
8.2.260.0070.01118.81
8.2.250.0050.00318.82
8.2.240.0060.00317.16
8.2.230.0060.00322.58
8.2.220.0030.00637.54
8.2.210.0110.00726.77
8.2.200.0060.00317.13
8.2.190.0120.00617.13
8.2.180.0120.00925.92
8.2.170.0070.00719.04
8.2.160.0030.01022.96
8.2.150.0000.00825.66
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0040.00421.23
8.2.110.0070.00321.23
8.2.100.0040.00718.03
8.2.90.0080.00318.09
8.2.80.0030.00518.03
8.2.70.0000.00817.93
8.2.60.0040.00418.28
8.2.50.0080.00018.10
8.2.40.0000.00819.85
8.2.30.0040.00418.22
8.2.20.0060.00320.34
8.2.10.0040.00418.02
8.2.00.0050.00219.41
8.1.330.0100.00921.75
8.1.320.0130.00716.20
8.1.310.0120.00318.50
8.1.300.0000.00818.16
8.1.290.0090.00318.88
8.1.280.0180.00025.92
8.1.270.0040.00423.99
8.1.260.0030.00526.35
8.1.250.0000.00728.09
8.1.240.0060.00322.48
8.1.230.0100.00022.66
8.1.220.0090.00017.79
8.1.210.0040.00418.77
8.1.200.0040.00717.73
8.1.190.0050.00317.60
8.1.180.0050.00318.10
8.1.170.0050.00317.62
8.1.160.0000.00818.98
8.1.150.0000.00718.92
8.1.140.0060.00317.65
8.1.130.0070.00018.90
8.1.120.0040.00417.51
8.1.110.0040.00417.59
8.1.100.0060.00317.54
8.1.90.0000.00717.58
8.1.80.0000.00917.60
8.1.70.0070.00017.61
8.1.60.0060.00317.71
8.1.50.0060.00317.66
8.1.40.0030.00517.66
8.1.30.0000.00817.76
8.1.20.0000.00817.64
8.1.10.0080.00317.57
8.1.00.0050.00517.57
8.0.300.0070.00020.09
8.0.290.0080.00016.75
8.0.280.0030.00618.51
8.0.270.0000.00716.92
8.0.260.0000.00718.45
8.0.250.0030.00317.13
8.0.240.0000.00817.25
8.0.230.0070.00017.00
8.0.220.0000.00717.19
8.0.210.0030.00617.15
8.0.200.0080.00017.09
8.0.190.0030.00517.18
8.0.180.0040.00417.25
8.0.170.0030.00617.19
8.0.160.0030.00617.13
8.0.150.0040.00416.89
8.0.140.0050.00517.04
8.0.130.0070.00317.05
8.0.120.0060.00316.95
8.0.110.0000.00916.98
8.0.100.0070.00317.18
8.0.90.0030.00617.19
8.0.80.0060.00317.05
8.0.70.0050.00516.99
8.0.60.0050.00517.16
8.0.50.0050.00617.11
8.0.30.0050.00516.99
8.0.20.0040.00817.18
8.0.10.0060.00617.27
7.4.330.0020.00215.55
7.4.320.0030.00316.82
7.4.300.0040.00416.77
7.4.290.0050.00316.85
7.4.280.0030.00516.69
7.4.270.0070.00416.68
7.4.260.0050.00516.84
7.4.250.0030.00616.84
7.4.240.0070.00316.74
7.4.230.0070.00316.75
7.4.220.0050.00516.79
7.4.210.0100.00016.78
7.4.200.0000.01016.75
7.4.190.0000.01016.71
7.4.180.0060.00316.69
7.4.160.0100.00016.80
7.4.150.0000.01216.74
7.4.140.0040.00716.61
7.4.130.0030.00816.58
7.4.120.0110.00416.59
7.4.110.0100.00316.66
7.4.100.0110.00516.73
7.4.90.0000.01216.68
7.4.80.0110.00516.58
7.4.70.0060.01016.71
7.4.60.0100.00516.55
7.4.50.0130.00016.65
7.4.40.0080.00516.61
7.4.30.0090.00316.65
7.4.20.0080.00516.73
7.4.10.0120.00016.58
7.4.00.0090.00316.77

preferences:
35.83 ms | 403 KiB | 5 Q