I have an array which contains some elements with two words, for example array("Dark Blue", "Carnation Pink").. What function do I need to use to search an array value that contains a specified string to be search. If I searched "Dark", the value "Dark Blue" should show.
2 Answers
You could use preg_grep().
$found = preg_grep('/\bDark\b/', $arr);
You could also use array_filter() and preg_match() with a regex..
$found = array_filter($arr, function($value) {
return preg_match('/\bDark\b/', $value);
});