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 (isset($m[$i][2])) { // immovable $result[$index] .= $m[$i][2]; // append to string } else { // movable from front while (--$j >= 0) { if (!isset($m[$j][2])) { // 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.0120.01020.37
8.4.150.0020.00014.05
8.4.140.0160.00717.89
8.4.130.0050.00418.62
8.4.120.0090.01123.89
8.4.110.0050.00619.02
8.4.100.0130.00818.11
8.4.90.0110.00920.38
8.4.80.0120.00720.78
8.4.70.0130.00719.15
8.4.60.0110.00922.29
8.4.50.0130.00722.39
8.4.40.0100.01018.05
8.4.30.0130.00720.86
8.4.20.0090.01218.21
8.4.10.0030.00917.97
8.3.280.0150.00618.82
8.3.270.0130.00816.96
8.3.260.0080.00916.85
8.3.250.0120.00719.12
8.3.240.0090.01017.50
8.3.230.0130.00516.89
8.3.220.0110.00720.69
8.3.210.0100.01016.75
8.3.200.0040.00416.78
8.3.190.0070.00820.48
8.3.180.0070.00219.07
8.3.170.0110.00717.45
8.3.160.0120.00616.86
8.3.150.0110.01117.08
8.3.140.0040.00419.00
8.3.130.0000.00816.73
8.3.120.0100.00719.18
8.3.110.0080.00020.94
8.3.100.0060.00324.06
8.3.90.0090.00626.77
8.3.80.0060.00316.75
8.3.70.0080.01116.75
8.3.60.0110.00417.00
8.3.50.0140.00718.22
8.3.40.0110.00420.21
8.3.30.0040.01119.09
8.3.20.0040.00424.18
8.3.10.0080.00024.66
8.3.00.0000.00826.16
8.2.290.0110.00917.38
8.2.280.0140.00520.67
8.2.270.0040.00416.73
8.2.260.0040.01116.94
8.2.250.0100.00618.82
8.2.240.0100.00019.18
8.2.230.0090.00022.58
8.2.220.0080.00037.54
8.2.210.0090.00926.77
8.2.200.0000.00916.88
8.2.190.0070.01018.73
8.2.180.0030.01325.92
8.2.170.0040.01119.20
8.2.160.0000.01422.96
8.2.150.0050.00525.66
8.2.140.0050.00324.66
8.2.130.0070.00026.16
8.2.120.0000.00818.96
8.2.110.0070.00321.09
8.2.100.0090.00318.09
8.2.90.0030.00619.91
8.2.80.0090.00019.03
8.2.70.0030.00517.75
8.2.60.0040.00418.16
8.2.50.0000.00918.07
8.2.40.0050.00618.18
8.2.30.0040.00418.14
8.2.20.0050.00320.57
8.2.10.0040.00417.99
8.2.00.0000.00719.33
8.1.330.0050.00321.92
8.1.320.0110.00822.18
8.1.310.0050.00316.88
8.1.300.0150.00618.09
8.1.290.0060.00318.88
8.1.280.0100.01025.92
8.1.270.0000.00824.66
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0070.00422.06
8.1.230.0110.00022.63
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0060.00317.38
8.1.190.0030.00517.60
8.1.180.0000.00818.10
8.1.170.0070.00318.69
8.1.160.0000.00718.93
8.1.150.0030.00518.86
8.1.140.0000.00717.62
8.1.130.0000.00717.62
8.1.120.0050.00217.64
8.1.110.0040.00417.52
8.1.100.0070.00017.57
8.1.90.0060.00317.61
8.1.80.0000.00717.50
8.1.70.0070.00017.67
8.1.60.0080.00017.76
8.1.50.0050.00517.64
8.1.40.0040.00417.72
8.1.30.0030.00717.64
8.1.20.0040.00417.71
8.1.10.0040.00417.75
8.1.00.0040.00417.66
8.0.300.0000.00718.77
8.0.290.0060.00317.00
8.0.280.0040.00318.41
8.0.270.0070.00019.99
8.0.260.0040.00217.02
8.0.250.0000.00817.15
8.0.240.0030.00517.25
8.0.230.0030.00317.16
8.0.220.0050.00217.02
8.0.210.0000.00717.16
8.0.200.0040.00417.19
8.0.190.0000.00817.16
8.0.180.0060.00617.19
8.0.170.0000.01017.04
8.0.160.0030.00517.27
8.0.150.0040.00417.00
8.0.140.0000.00717.08
8.0.130.0040.00417.05
8.0.120.0030.00317.15
8.0.110.0040.00417.05
8.0.100.0000.00717.05
8.0.90.0000.00717.18
8.0.80.0040.00417.10
8.0.70.0000.00717.13
8.0.60.0040.00417.05
8.0.50.0040.00417.05
8.0.30.0020.00516.99
8.0.20.0040.00417.12
8.0.10.0000.00717.05
7.4.330.0030.00315.55
7.4.320.0040.00416.85
7.4.300.0000.00616.78
7.4.290.0000.00716.84
7.4.280.0000.00916.79
7.4.270.0080.00016.73
7.4.260.0030.00316.87
7.4.250.0030.00316.83
7.4.240.0030.00516.82
7.4.230.0030.00316.72
7.4.220.0030.00516.85
7.4.210.0030.00516.76
7.4.200.0030.00316.83
7.4.190.0000.00816.69
7.4.180.0030.00316.61
7.4.160.0000.00816.81
7.4.150.0040.00416.75
7.4.140.0030.00316.62
7.4.130.0050.00216.72
7.4.120.0040.00416.71
7.4.110.0000.00816.55
7.4.100.0000.00816.80
7.4.90.0050.00216.58
7.4.80.0070.00016.77
7.4.70.0030.00316.59
7.4.60.0030.00316.59
7.4.50.0050.00316.66
7.4.40.0070.00016.63
7.4.30.0040.00416.62
7.4.20.0070.00016.66
7.4.10.0000.00716.70
7.4.00.0000.00716.73

preferences:
122.78 ms | 403 KiB | 5 Q