How can i check if a $string
contains any of the items expressed in an array?
$string = 'My nAmE is Tom.';
$array = array("name","tom");
if(contains($string,$array))
{
// do something to say it contains
}
Any ideas?
How can i check if a $string
contains any of the items expressed in an array?
$string = 'My nAmE is Tom.';
$array = array("name","tom");
if(contains($string,$array))
{
// do something to say it contains
}
Any ideas?
Another way to do with array_intersect() function, Try below code :
is that what you wanted? i hope that code is compiling :)
I don't think there is a built-in function that will handle what you want. You could easily write a
contains()
function however:Something like this would work:
Using the accepted answer:
Just a side note that the if statement could be changed to:
since it's not really necessary to use array_map to apply
strtolower
to each element. instead apply it to the initial string.