I thought this would be a simple thing to do with a native php function but i’ve found a few different, all quite complicated, ways that people have tried to achieve it. What’s the most efficient way of checking if a string contains one or more elements in an array? i.e, below – where $data[‘description’] is a string. Obv the in_array check below breaks because it expects param 2 to be an array
$keywords = array(
'bus',
'buses',
'train',
);
if (!in_array($keywords, $data['description']))
continue;
Assuming that the String is a collapsed/delimited list of values
Example 1:
Example 2:
Assuming that the String is plain text, and you are simply looking for instances of the specified words inside it
Example 1:
Example 2: