Looking to search a body of text and return the keys of any of the array elements that have been found within the text. I currently have the below which works but only returns True on the first element found.
$needles = [1 => 'shed', 5 => 'charge', 8 => 'book', 9 => 'car'];
$text = "Does anyone know how much Bentleys charge to put up a small shed please? Thanks";
if(preg_match('/'.implode('|', array_map('preg_quote', $needles)).'/i', $text)) {
echo "Match Found!";
}
However the output I need is;
[1 => 'shed', 5 => 'charge']
Can anybody help? I am going to be searching a lot of values so this needs to be a fast solution hence using preg_match.