In the following example, the result is FOUND
.
I want however to make 1 change to this, to echo found
when the $string = 'welc to my city'
that means that if the string contains some of the letters of a word found in the array.
$string = 'welcome to my city';
$array = array("welcome","sunny");
if(0 < count(array_intersect(explode(' ', strtolower($string)), $array))) {
echo 'found';
}
Examples
welcome to my city // true
welc to my city //true
welcomelkjdfs to my city //true
hi how are you // false
is it sunny? // true
what a big bright sun //true
I can't say about one change. But here is solution in one line
if(0 < count(
array_filter(
array_map(function ($value) use ($array) {
foreach ($array as $word) {
if (strpos($word, $value) !== false || strpos($value, $word) !== false) {
return true;
}
}
}, explode(' ', $string)))
)
) {
echo 'found';
};