3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr= ["clownfish.jpg", "clownfish-150x150.jpg", "b800-768x575.jpg", "b800-4.jpg", "b800.jpg", "agility_3.jpg", "agility_3-45x45.jpg", "hundezubehör-für-sommer.jpg"]; $find = "hundezubehör-für-sommer.jpg"; var_dump(in_array($find, $arr)); Foreach($arr as $key => $item){ $length = min(strlen($item), strlen($find))-4; // lenght of the smallest string - ".jpg" if(levenshtein(substr($item,0,$length), substr($find,0,$length), 1,1,0) == 0){ //is it the same file $len = [strlen($item) => $item, strlen($find) => $find]; // make a associative array with lenght as key $minkey = min(array_keys($len)); // find the smallest of them $new[] = $len[$minkey]; // add the smallest to the new array } } Var_dump(array_unique($new)); // remove duplicates

preferences:
24.64 ms | 410 KiB | 5 Q