Must be simple but cant find my answer.
How to test whether one of the values in the array is contained in the string?
Output should be true or false.
$array = Array(
0 => 'word1',
1 => 'word2',
2 => 'New York'
3 => 'New car'
);
$string = "Its a sunny day in New York";
Trying to clarify. In this case array[3] should not be a match. Only array[2] should be.
Update:
A word boundary independent solution would be to add spaces around the input string and the search words:
or by looping over the terms:
Both can be put in a function to simplify the use, e.g.
Have a look at a DEMO
Old answer:
You could use regular expressions:
The important part are the boundary characters
\bhere. You will only get a match if the value you search for is a (sequence of) word(s) in the string.