3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fruits = array("apple","orange","papaya","grape","apple juice", "applecurd"); $content = "eaplp"; $start = microtime(true); function sorted($s) { $a = str_split($s); sort($a); return implode("", $a); } $pos = array_search(sorted($content), array_map("sorted", $fruits)); echo ($pos !== false) ? "$fruits[$pos] found.\n" : "not found.\n"; echo (microtime(true)-$start)*100 . "\n\n"; $fruits = array("apple","orange","papaya","grape","apple juice", "applecurd"); $content = "eaplp"; $start2 = microtime(true); $content = str_split($content); $count = count($content); Foreach($fruits as $fruit){ $arr_fruit = str_split($fruit); $SortCont = array_merge(array_intersect($arr_fruit, $content), array_diff($content, $arr_fruit)); If(array_slice($SortCont, 0, $count) == array_slice($arr_fruit, 0, $count)){ Echo "match: " . $fruit ."\n"; } } echo (microtime(true)-$start2)*100;
based on H6UNd
Output for 7.3.1
apple found. 0.0068902969360352 match: apple match: apple juice match: applecurd 0.004887580871582
Output for 7.3.0
apple found. 0.0040054321289062 match: apple match: apple juice match: applecurd 0.002598762512207
Output for 7.2.13
apple found. 0.0048160552978516 match: apple match: apple juice match: applecurd 0.0027894973754883
Output for 7.2.12
apple found. 0.0056028366088867 match: apple match: apple juice match: applecurd 0.0036001205444336
Output for 7.2.11
apple found. 0.0050067901611328 match: apple match: apple juice match: applecurd 0.0030040740966797
Output for 7.2.10
apple found. 3.1139850616455 match: apple match: apple juice match: applecurd 0.0065088272094727
Output for 7.2.9
apple found. 0.0092983245849609 match: apple match: apple juice match: applecurd 0.0066995620727539
Output for 7.2.8
apple found. 0.0072956085205078 match: apple match: apple juice match: applecurd 0.0041961669921875
Output for 7.2.7
apple found. 0.0065088272094727 match: apple match: apple juice match: applecurd 0.0049114227294922
Output for 7.2.6
apple found. 0.0053167343139648 match: apple match: apple juice match: applecurd 0.0029087066650391
Output for 7.2.5
apple found. 0.0049114227294922 match: apple match: apple juice match: applecurd 0.0027894973754883
Output for 7.2.4
apple found. 2.1070003509521 match: apple match: apple juice match: applecurd 0.0078201293945312
Output for 7.2.3
apple found. 0.007319450378418 match: apple match: apple juice match: applecurd 0.0077009201049805
Output for 7.2.2
apple found. 0.0053882598876953 match: apple match: apple juice match: applecurd 0.0027894973754883
Output for 7.2.1
apple found. 0.0047922134399414 match: apple match: apple juice match: applecurd 0.0033855438232422
Output for 7.2.0
apple found. 0.0082015991210938 match: apple match: apple juice match: applecurd 0.0085115432739258
Output for 7.1.25
apple found. 0.0045061111450195 match: apple match: apple juice match: applecurd 0.0027894973754883
Output for 7.1.16
apple found. 0.0053882598876953 match: apple match: apple juice match: applecurd 0.0045061111450195
Output for 7.1.15
apple found. 0.0077009201049805 match: apple match: apple juice match: applecurd 0.0063896179199219
Output for 7.1.14
apple found. 0.010395050048828 match: apple match: apple juice match: applecurd 0.01671314239502
Output for 7.1.13
apple found. 0.0058889389038086 match: apple match: apple juice match: applecurd 0.0040054321289062
Output for 7.1.12
apple found. 0.013995170593262 match: apple match: apple juice match: applecurd 0.018882751464844
Output for 7.1.11
apple found. 0.0092983245849609 match: apple match: apple juice match: applecurd 0.01070499420166
Output for 7.1.10
apple found. 0.0051975250244141 match: apple match: apple juice match: applecurd 0.013303756713867
Output for 7.1.9
apple found. 0.018405914306641 match: apple match: apple juice match: applecurd 0.029802322387695
Output for 7.1.8
apple found. 0.0054121017456055 match: apple match: apple juice match: applecurd 0.004887580871582
Output for 7.1.7
apple found. 0.005793571472168 match: apple match: apple juice match: applecurd 0.0056028366088867
Output for 7.1.6
apple found. 0.0050067901611328 match: apple match: apple juice match: applecurd 0.0068902969360352
Output for 7.1.5
apple found. 0.013184547424316 match: apple match: apple juice match: applecurd 0.019001960754395
Output for 7.1.4
apple found. 0.0074863433837891 match: apple match: apple juice match: applecurd 0.010299682617188
Output for 7.1.3
apple found. 0.0053167343139648 match: apple match: apple juice match: applecurd 0.007176399230957
Output for 7.1.2
apple found. 0.0066995620727539 match: apple match: apple juice match: applecurd 0.010490417480469
Output for 7.1.1
apple found. 0.011014938354492 match: apple match: apple juice match: applecurd 0.017499923706055
Output for 7.1.0
apple found. 0.008392333984375 match: apple match: apple juice match: applecurd 0.01988410949707