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
Output for 7.1.0 - 7.1.22, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
bool(true) array(1) { [0]=> string(29) "hundezubehör-für-sommer.jpg" }
Output for 8.3.5
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" }

preferences:
162.83 ms | 402 KiB | 170 Q