3v4l.org

run code in 300+ 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");

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.60.0110.00418.41
8.3.50.0140.00718.12
8.3.40.0040.01118.71
8.3.30.0170.00318.98
8.3.20.0050.00320.20
8.3.10.0090.00023.71
8.3.00.0050.00318.96
8.2.180.0070.01416.50
8.2.170.0070.01119.00
8.2.160.0140.00022.96
8.2.150.0040.00424.18
8.2.140.0150.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00021.19
8.2.110.0050.00521.08
8.2.100.0040.00717.78
8.2.90.0070.00020.59
8.2.80.0030.00617.97
8.2.70.0030.00517.93
8.2.60.0030.00618.16
8.2.50.0100.00018.10
8.2.40.0060.00320.94
8.2.30.0000.00719.19
8.2.20.0060.00317.68
8.2.10.0020.00518.20
8.2.00.0040.00417.75
8.1.280.0070.01025.92
8.1.270.0040.00418.96
8.1.260.0030.00626.35
8.1.250.0080.00028.09
8.1.240.0030.00619.45
8.1.230.0110.00020.97
8.1.220.0090.00017.74
8.1.210.0040.00419.04
8.1.200.0030.00617.35
8.1.190.0080.00017.11
8.1.180.0050.00318.10
8.1.170.0000.00818.37
8.1.160.0070.00020.67
8.1.150.0060.00318.89
8.1.140.0050.00419.22
8.1.130.0070.00017.76
8.1.120.0000.00717.55
8.1.110.0030.00617.43
8.1.100.0040.00417.35
8.1.90.0000.00717.48
8.1.80.0000.00717.36
8.1.70.0050.00317.39
8.1.60.0000.00917.66
8.1.50.0000.00817.50
8.1.40.0040.00417.54
8.1.30.0080.00017.71
8.1.20.0040.00417.65
8.1.10.0000.00817.43
8.1.00.0050.00217.39
8.0.300.0040.00419.93
8.0.290.0040.00416.63
8.0.280.0030.00518.46
8.0.270.0040.00417.20
8.0.260.0000.00717.12
8.0.250.0070.00017.08
8.0.240.0040.00417.02
8.0.230.0030.00316.93
8.0.220.0000.00716.94
8.0.210.0000.00717.02
8.0.200.0030.00616.91
8.0.190.0000.00816.86
8.0.180.0000.00716.82
8.0.170.0050.00216.85
8.0.160.0070.00016.90
8.0.150.0030.00316.71
8.0.140.0040.00416.85
8.0.130.0030.00313.32
8.0.120.0080.00016.84
8.0.110.0040.00416.79
8.0.100.0040.00416.88
8.0.90.0070.00017.02
8.0.80.0070.01016.91
8.0.70.0040.00416.89
8.0.60.0030.00616.70
8.0.50.0000.00716.77
8.0.30.0110.01216.99
8.0.20.0180.00617.40
8.0.10.0070.00016.82
8.0.00.0070.01316.65
7.4.330.0000.00515.03
7.4.320.0060.00016.50
7.4.300.0000.00616.52
7.4.290.0030.00316.60
7.4.280.0000.00816.41
7.4.270.0070.00016.56
7.4.260.0030.00316.60
7.4.250.0040.00416.50
7.4.240.0020.00516.50
7.4.230.0030.00316.35
7.4.220.0150.00916.52
7.4.210.0090.00616.44
7.4.200.0000.00716.64
7.4.160.0090.00616.54
7.4.150.0070.01817.40
7.4.140.0110.00717.86
7.4.130.0090.00716.48
7.4.120.0060.01316.50
7.4.110.0120.00916.63
7.4.100.0090.00916.37
7.4.90.0030.01416.60
7.4.80.0110.01119.39
7.4.70.0090.01216.70
7.4.60.0080.00816.64
7.4.50.0030.00616.51
7.4.40.0070.01016.58
7.4.30.0130.01016.40
7.4.00.0050.01114.99
7.3.330.0060.00013.24
7.3.320.0050.00013.17
7.3.310.0030.00316.43
7.3.300.0080.00016.37
7.3.290.0070.00716.34
7.3.280.0080.01016.35
7.3.270.0090.00917.40
7.3.260.0040.01916.48
7.3.250.0090.00716.54
7.3.240.0100.00616.35
7.3.230.0090.00616.43
7.3.210.0030.01316.41
7.3.200.0030.01419.39
7.3.190.0060.01316.37
7.3.180.0140.01116.51
7.3.170.0100.00716.44
7.3.160.0030.01616.41
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.330.0070.01016.60
7.2.320.0160.00016.72
7.2.310.0040.01316.43
7.2.300.0050.01416.73
7.2.290.0070.01416.73
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

preferences:
64.6 ms | 400 KiB | 5 Q