3v4l.org

run code in 200+ PHP versions simultaneously
<?php /** * Re-order the characters from $T using the order of characters in $O. * * @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");
based on qqiO5

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.00.0050.01114.99
7.3.120.0030.00915.09
7.3.110.0130.00315.05
7.3.100.0100.01014.89
7.3.90.0070.00714.79
7.3.80.0070.01014.61
7.3.70.0070.00314.86
7.3.60.0040.01414.56
7.3.50.0070.01014.71
7.3.40.0140.00014.75
7.3.30.0090.00614.87
7.3.20.0090.00616.32
7.3.10.0030.00616.84
7.3.00.0110.00316.49
7.2.250.0120.00515.02
7.2.240.0060.01214.98
7.2.230.0080.00814.77
7.2.220.0060.01015.13
7.2.210.0040.01415.32
7.2.200.0040.00814.81
7.2.190.0000.01715.06
7.2.180.0000.01214.90
7.2.170.0040.00715.10
7.2.110.0120.00816.70
7.2.80.0100.00316.75
7.2.60.0070.01016.75
7.1.330.0070.00716.05
7.1.320.0060.00616.02
7.1.310.0060.00916.08
7.1.300.0070.00715.81
7.1.290.0090.00915.85
7.1.280.0110.00315.69
7.1.270.0070.01015.91
7.1.260.0120.00315.55
7.1.200.0040.01115.75
7.1.70.0070.00717.02
7.1.60.0040.02219.46
7.1.50.0090.01517.06
7.1.00.0100.07022.41
7.0.200.0000.00716.72
7.0.140.0000.03322.00
7.0.70.0070.08021.76
7.0.60.0030.08721.69
7.0.50.0030.04720.33
7.0.40.0000.04720.04
7.0.30.0030.04020.13
7.0.20.0030.04720.05
7.0.10.0030.04320.04
7.0.00.0000.04320.17
5.6.280.0030.07321.00
5.6.220.0130.07020.73
5.6.210.0000.05720.66
5.6.200.0000.05721.08
5.6.190.0030.04021.04
5.6.180.0070.05321.03
5.6.170.0070.04021.04
5.6.160.0070.03721.04
5.6.150.0000.04321.01
5.6.140.0030.04320.95
5.6.130.0100.06021.05
5.6.120.0000.07321.05
5.6.110.0100.04020.96
5.6.100.0070.04320.93
5.6.90.0070.04021.02
5.6.80.0030.04020.43
5.6.70.0030.04020.46
5.6.60.0030.04020.40
5.6.50.0000.04020.40
5.6.40.0000.05320.39
5.6.30.0030.03720.41
5.6.20.0000.05320.32
5.6.10.0070.03320.30
5.6.00.0030.06320.35
5.5.360.0030.08320.50
5.5.350.0000.07020.48
5.5.340.0100.07320.87
5.5.330.0000.04320.90
5.5.320.0030.04320.90
5.5.310.0070.03720.78
5.5.300.0070.04020.92
5.5.290.0070.08320.87
5.5.280.0070.08020.76
5.5.270.0030.07720.82
5.5.260.0030.04020.89
5.5.250.0070.04020.61
5.5.240.0030.05020.27
5.5.230.0170.02720.16
5.5.220.0000.04020.21
5.5.210.0030.03720.12
5.5.200.0070.03320.15
5.5.190.0000.04020.19
5.5.180.0070.06320.29
5.5.160.0000.04020.25
5.5.150.0030.04020.27
5.5.140.0070.03720.19
5.5.130.0030.03720.28
5.5.120.0070.03320.17
5.5.110.0030.03720.15
5.5.100.0030.03720.14
5.5.90.0000.04020.12
5.5.80.0000.03720.12
5.5.70.0070.03319.94
5.5.60.0030.03320.16
5.5.50.0030.03720.02
5.5.40.0000.05020.01
5.5.30.0070.07720.15
5.5.20.0000.07020.16
5.5.10.0030.08020.08
5.5.00.0030.07719.96
5.4.450.0030.06719.36
5.4.440.0030.08319.42
5.4.430.0030.05319.47
5.4.420.0000.04019.37
5.4.410.0030.06319.24
5.4.400.0030.03719.18
5.4.390.0030.03718.95
5.4.380.0030.03719.13
5.4.370.0030.03318.95
5.4.360.0000.04019.09
5.4.350.0000.03719.23
5.4.340.0000.04318.95
5.4.320.0000.04318.88
5.4.310.0000.03719.20
5.4.300.0030.03018.85
5.4.290.0070.03319.20
5.4.280.0030.03719.23
5.4.270.0030.03319.04
5.4.260.0000.03719.13
5.4.250.0070.03318.84
5.4.240.0000.04318.87
5.4.230.0070.03719.11
5.4.220.0000.03318.89
5.4.210.0030.03319.04
5.4.200.0000.04319.04
5.4.190.0070.06019.03
5.4.180.0030.05319.20
5.4.170.0100.07719.11
5.4.160.0070.07719.02
5.4.150.0070.07719.16
5.4.140.0000.06016.38
5.4.130.0030.05316.46
5.4.120.0030.07316.40
5.4.110.0000.05316.53
5.4.100.0030.07316.40
5.4.90.0030.04716.38
5.4.80.0030.07316.56
5.4.70.0070.06316.54
5.4.60.0030.07316.42
5.4.50.0070.07016.41
5.4.40.0030.04016.41
5.4.30.0070.05016.27
5.4.20.0100.06716.47
5.4.10.0000.07316.39
5.4.00.0070.07015.63
5.3.290.0000.03714.73
5.3.280.0000.03714.74
5.3.270.0070.07714.67
5.3.260.0030.07714.66
5.3.250.0030.07714.68
5.3.240.0070.07314.61
5.3.230.0000.08014.74
5.3.220.0030.07014.66
5.3.210.0030.07314.59
5.3.200.0030.03714.62
5.3.190.0170.07314.53
5.3.180.0030.07714.46
5.3.170.0030.08014.52
5.3.160.0030.06314.58
5.3.150.0000.05314.63
5.3.140.0000.07314.55
5.3.130.0000.08014.61
5.3.120.0100.05714.51
5.3.110.0030.06014.47
5.3.100.0000.05713.99
5.3.90.0100.07314.11
5.3.80.0030.08014.07
5.3.70.0070.06014.08
5.3.60.0070.05013.94
5.3.50.0030.03713.86
5.3.40.0000.08013.86
5.3.30.0000.08014.03
5.3.20.0000.06713.84
5.3.10.0070.04713.55
5.3.00.0030.07313.77
5.2.170.0030.06312.32
5.2.160.0000.06712.32
5.2.150.0030.06012.32
5.2.140.0100.05712.32
5.2.130.0030.03712.32
5.2.120.0030.06012.32
5.2.110.0000.06012.32
5.2.100.0000.05712.32
5.2.90.0000.06012.32
5.2.80.0030.05012.32
5.2.70.0000.06012.32
5.2.60.0070.06312.32
5.2.50.0000.06012.32
5.2.40.0030.05712.32
5.2.30.0030.05712.32
5.2.20.0030.04312.32
5.2.10.0000.06712.32
5.2.00.0000.03712.32
5.1.60.0000.02712.32
5.1.50.0030.05312.32
5.1.40.0030.04712.32
5.1.30.0000.04012.32
5.1.20.0000.04012.32
5.1.10.0000.05312.32
5.1.00.0000.05712.32
5.0.50.0030.03012.32
5.0.40.0030.04312.32
5.0.30.0000.07012.32
5.0.20.0030.02712.32
5.0.10.0030.04312.32
5.0.00.0030.05312.32
4.4.90.0070.02312.32
4.4.80.0030.03712.32
4.4.70.0070.02312.32
4.4.60.0000.03712.32
4.4.50.0070.03312.32
4.4.40.0000.02712.32
4.4.30.0000.03712.32
4.4.20.0000.03312.32
4.4.10.0000.03712.32
4.4.00.0000.04312.32
4.3.110.0000.02712.32
4.3.100.0030.02312.32
4.3.90.0030.03012.32
4.3.80.0000.04012.32
4.3.70.0000.02712.32
4.3.60.0030.02312.32
4.3.50.0000.03712.32
4.3.40.0000.05012.32
4.3.30.0000.02712.32
4.3.20.0070.03712.32
4.3.10.0000.03712.32
4.3.00.0030.03012.32