<?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
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
bool(true)
array(1) {
[0]=>
string(29) "hundezubehör-für-sommer.jpg"
}