I am attempting to search an array using preg_grep for any values which contain all the words listed in my pattern, in any order.
Assuming the words I want to search for are as follows: apple pear banana
I have tried:
$result = preg_grep("/(apple|pear|banana)/i", $array);
Which returns strings that contain any of the three words
$result = preg_grep("/(apple.*pear.*banana)/i", $array);
Which returns strings that contain all 3, but they must be in order.
How to perform unordered preg_grep?