3v4l.org

run code in 300+ 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)
8.3.60.0040.01118.56
8.3.50.0100.01018.29
8.3.40.0140.00018.84
8.3.30.0150.00619.04
8.3.20.0070.00020.21
8.3.10.0000.00823.48
8.3.00.0030.00519.02
8.2.180.0090.00616.50
8.2.170.0080.01222.96
8.2.160.0070.01020.58
8.2.150.0070.00024.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0070.00021.05
8.2.110.0060.00322.24
8.2.100.0090.00319.89
8.2.90.0000.00819.12
8.2.80.0000.00817.97
8.2.70.0030.00517.50
8.2.60.0040.00417.93
8.2.50.0080.00018.07
8.2.40.0080.00018.22
8.2.30.0000.00718.01
8.2.20.0030.00517.81
8.2.10.0040.00418.20
8.2.00.0000.00717.68
8.1.280.0070.01025.92
8.1.270.0000.00818.88
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0050.00323.70
8.1.230.0080.00419.00
8.1.220.0000.00817.74
8.1.210.0030.00618.77
8.1.200.0070.00317.36
8.1.190.0030.00617.23
8.1.180.0060.00318.10
8.1.170.0060.00318.51
8.1.160.0000.00821.99
8.1.150.0000.00718.78
8.1.140.0000.00919.31
8.1.130.0030.00517.84
8.1.120.0040.00417.51
8.1.110.0000.00817.52
8.1.100.0040.00417.34
8.1.90.0050.00217.43
8.1.80.0070.00017.43
8.1.70.0000.00717.38
8.1.60.0050.00517.67
8.1.50.0080.00017.54
8.1.40.0000.00717.52
8.1.30.0000.00817.70
8.1.20.0040.00417.59
8.1.10.0080.00017.55
8.1.00.0050.00317.32
8.0.300.0070.00018.77
8.0.290.0000.00716.75
8.0.280.0070.00018.45
8.0.270.0000.00717.14
8.0.260.0000.00717.30
8.0.250.0000.00716.94
8.0.240.0020.00516.90
8.0.230.0000.00716.90
8.0.220.0040.00417.00
8.0.210.0000.00716.85
8.0.200.0030.00616.87
8.0.190.0040.00416.99
8.0.180.0080.00016.81
8.0.170.0000.00816.93
8.0.160.0000.00716.86
8.0.150.0000.00716.79
8.0.140.0080.00016.79
8.0.130.0000.00713.37
8.0.120.0030.00616.90
8.0.110.0060.00316.92
8.0.100.0050.00216.87
8.0.90.0000.00816.89
8.0.80.0160.00616.93
8.0.70.0040.00416.73
8.0.60.0040.00416.68
8.0.50.0000.00816.72
8.0.30.0160.00716.99
8.0.20.0130.01017.40
8.0.10.0000.00816.87
8.0.00.0090.01016.92
7.4.330.0040.00015.03
7.4.320.0060.00016.41
7.4.300.0000.00616.51
7.4.290.0050.00216.62
7.4.280.0030.00616.44
7.4.270.0070.00016.51
7.4.260.0070.00016.50
7.4.250.0000.00716.49
7.4.240.0070.00016.57
7.4.230.0000.00816.41
7.4.220.0090.00916.65
7.4.210.0100.00716.64
7.4.200.0070.00016.51
7.4.160.0070.00716.64
7.4.150.0140.01317.40
7.4.140.0100.00817.86
7.4.130.0030.01416.49
7.4.120.0120.00516.58
7.4.110.0170.00716.36
7.4.100.0100.01016.55
7.4.90.0060.01316.45
7.4.80.0140.00719.39
7.4.70.0130.00716.51
7.4.60.0110.00516.68
7.4.50.0030.00316.48
7.4.40.0100.00716.60
7.4.30.0150.00916.59
7.4.00.0070.01014.71
7.3.330.0050.00013.35
7.3.320.0060.00013.19
7.3.310.0030.00316.38
7.3.300.0000.00716.38
7.3.290.0080.00616.38
7.3.280.0120.00516.35
7.3.270.0170.00017.40
7.3.260.0070.01016.35
7.3.250.0120.00616.50
7.3.240.0060.00916.79
7.3.230.0100.00716.39
7.3.210.0000.01716.65
7.3.200.0060.01219.39
7.3.190.0090.00616.51
7.3.180.0070.01416.50
7.3.170.0160.00316.55
7.3.160.0120.00316.50
7.2.330.0110.00616.70
7.2.320.0100.00616.77
7.2.310.0090.00616.54
7.2.300.0060.01516.79
7.2.290.0070.01016.79
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

preferences:
34.94 ms | 400 KiB | 5 Q