Correct syntax for matching a string inside a variable against an array
- by Jamex
Hi,
I have a variable, $var, that contains a string of characters, this is a dynamic variable that contains the values from inputs.
$var could be 'abc', or $var could be 'blu',
I want to match the string inside variable against an array, and return all the matches.
$array = array("blue", "red", "green");
What is the correct syntax for writing the code in php, my rough code is below
$match = preg_grep($var, $array); (incorrect syntax of course)
I tried to put quotes and escape slashes, but so far no luck. Any suggestion?
TIA