3v4l.org

run code in 200+ PHP versions simultaneously
<?php /** * @param string $T the string to re-order * @param string $O the string that specifies the desired order * @return string the re-ordered $T */ function reorder($T, $O) { // Convert $T and $O to arrays of characters $t = str_split($T); $o = str_split($O); // Compute the index of each character from $T in $O // Use -1 for characters that do not appear in $O $m = array_map(function($x) use ($o) { $p = array_search($x, $o); return ($p === FALSE) ? -1 : $p; }, $t ); // Sort $m and $t simultaneously; $t will follow the changes applied to $m array_multisort($m, $t); // Join the sorted characters of $T back and return as string return implode('', $t); } $order = 'eloh'; echo('hello => '.reorder('hello', $order)."\n"); echo('help => '.reorder('help', $order)."\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)
7.4.60.0110.00516.68
7.4.50.0030.00316.48
7.4.00.0070.01014.71
7.3.180.0070.01416.50
7.2.60.0030.00917.02
7.2.00.0070.00719.25
7.1.200.0080.00315.87
7.1.100.0000.01018.01
7.1.70.0030.01217.40
7.1.60.0110.01419.46
7.1.50.0090.01216.66
7.1.00.0030.07722.46
7.0.200.0030.00616.72
7.0.140.0000.03722.19
7.0.60.0070.06720.04
7.0.50.0100.07717.89
7.0.40.0030.08720.09
7.0.30.0300.04720.21
7.0.20.0230.04720.25
7.0.10.0130.04020.19
7.0.00.0100.05320.18
5.6.280.0000.07720.98
5.6.210.0070.04720.48
5.6.200.0030.08318.16
5.6.190.0200.02720.48
5.6.180.0370.06320.33
5.6.170.0300.04320.56
5.6.160.0030.08720.50
5.6.150.0000.05318.22
5.6.140.0130.07718.15
5.6.130.0030.04718.14
5.6.120.0100.05320.99
5.6.110.0030.09021.13
5.6.100.0100.08720.99
5.6.90.0130.07720.89
5.6.80.0030.05020.38
5.5.350.4300.03720.43
5.5.340.0000.07717.98
5.5.330.0100.04020.57
5.5.320.0230.07720.27
5.5.310.0400.07020.23
5.5.300.0130.07718.05
5.5.290.0070.06018.07
5.5.280.0130.07320.79
5.5.270.0070.04320.98
5.5.260.0030.08720.88
5.5.250.0130.05020.79
5.5.240.0070.07320.16
5.4.450.0830.05719.20
5.4.440.0630.06019.29
5.4.430.0670.06319.43
5.4.420.0870.04719.29
5.4.410.0670.06319.10
5.4.400.0230.04319.22
5.4.390.0200.05318.79
5.4.380.0200.06018.74
5.4.370.0270.06018.73
5.4.360.0200.05718.61
5.4.350.0270.05018.61
5.4.340.0330.04718.80
5.4.320.0400.06318.81
5.4.310.0170.08318.78
5.4.300.0270.07718.61
5.4.290.0300.06718.63
5.4.280.0400.03718.69
5.4.270.0300.04718.61
5.4.260.0270.05318.61
5.4.250.0270.05018.53
5.4.240.0170.06718.79
5.4.230.0300.05018.46
5.4.220.0300.05318.49
5.4.210.0100.06318.73
5.4.200.0170.06016.64
5.4.190.0300.05318.48
5.4.180.0300.05018.61
5.4.170.0270.05718.79
5.4.160.0130.05718.68
5.4.150.0200.05018.55
5.4.140.0130.05716.35
5.4.130.0130.05716.30
5.4.120.0300.05016.30
5.4.110.0100.05716.27
5.4.100.0270.04316.25
5.4.90.0270.04316.27
5.4.80.0170.05316.15
5.4.70.0200.05316.43
5.4.60.0170.06316.40
5.4.50.0200.05316.26
5.4.40.0230.04716.41
5.4.30.0200.05016.25
5.4.20.0200.05716.39
5.4.10.0200.05316.25
5.4.00.0100.06315.66
5.3.290.0130.06314.70
5.3.280.0270.05014.71
5.3.270.0170.06014.59
5.3.260.0230.07314.65
5.3.250.0270.06714.70
5.3.240.0230.07014.65
5.3.230.0400.06014.73
5.3.220.0400.05714.70
5.3.210.0400.06014.57
5.3.200.0270.04714.79
5.3.190.0170.05714.60
5.3.180.0200.05714.59
5.3.170.0270.05714.59
5.3.160.0200.05014.59
5.3.150.0200.05314.69
5.3.140.0070.06314.76
5.3.130.0130.06314.53
5.3.120.0230.06014.57
5.3.110.0130.06314.77
5.3.100.0100.06014.14
5.3.90.0170.07014.05
5.3.80.0330.04314.01
5.3.70.0230.05314.25
5.3.60.0130.06314.01
5.3.50.0230.05314.17
5.3.40.0300.04014.04
5.3.30.0270.04713.95
5.3.20.0130.05713.87
5.3.10.0200.05013.69
5.3.00.0200.06013.88
5.2.170.0100.05311.18
5.2.160.0330.03711.24
5.2.150.0130.05011.16
5.2.140.0170.05011.16
5.2.130.0200.03711.14
5.2.120.0230.03311.11
5.2.110.0200.04011.31
5.2.100.0270.04011.14
5.2.90.0200.04711.30
5.2.80.0270.05311.11
5.2.70.0100.05011.16
5.2.60.0170.04311.27
5.2.50.0170.04311.14
5.2.40.0230.03711.05
5.2.30.0230.03711.18
5.2.20.0230.03310.98
5.2.10.0170.05010.97
5.2.00.0200.05710.73
5.1.60.0170.04710.02
5.1.50.0100.03710.17
5.1.40.0130.03710.11
5.1.30.0170.04310.36
5.1.20.0130.03710.47
5.1.10.0230.03010.09
5.1.00.0230.02710.09
5.0.50.0070.0308.59
5.0.40.0130.0238.55
5.0.30.0100.0438.26
5.0.20.0070.0338.22
5.0.10.0070.0338.17
5.0.00.0030.0508.19
4.4.90.0100.0205.98
4.4.80.0070.0235.98
4.4.70.0170.0135.95
4.4.60.0130.0205.88
4.4.50.0100.0205.96
4.4.40.0070.0405.87
4.4.30.0100.0205.90
4.4.20.0100.0235.95
4.4.10.0070.0335.98
4.4.00.0070.0435.91
4.3.110.0100.0305.86
4.3.100.0100.0305.85
4.3.90.0070.0235.77
4.3.80.0130.0405.88
4.3.70.0100.0235.80
4.3.60.0100.0235.80
4.3.50.0070.0235.92
4.3.40.0170.0235.80
4.3.30.0030.0274.59
4.3.20.0030.0274.59
4.3.10.0070.0174.54
4.3.00.0130.0206.79