I have sample function for searching words from array with specified letters:
public static function getWords($words, $specifed_letters)
{
$pattern = is_array($specifed_letters) ? '/[' . implode("",
$specifed_letters) . ']/u' : '/[' .$specifed_letters. ']/u';
$result = preg_grep($pattern, $array_words);
return $result;
}
Example usage:
$words = ["apple", "sample", "app", "тоҷик", "отабек", "баҳодурбек"];
$result = getWords($words, $letters = ['l', 's']);
This example will return words: apple, sample
.
Because in this words have letters "l"
or "s"
.
How I can search words where have all specifed letters in word?
For example if I add to specifed letters "app"
then from words array must be return words: app, apple
.
And how search word with only specifed letters. For example I will write word "app"
in shuffled
variant "pap"
. And how I can get on result only word "app"
without "apple"
?