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;

preferences:
32.08 ms | 402 KiB | 5 Q