I want to return array that does not contains a list of characters.
Below code works fine for one keyword ('bc'
).
$array = array("abc", "def", "ghi");
$filterArray = array_filter($array, function ($var) {return(strpos($var, 'bc') === false);});
print_r($filterArray);
However, below code does not work when I try to filter out multiple keywords by using $excludeKeyword_arr
and foreach
.
$array = array("abc", "def", "ghi");
$excludeKeyword_arr = ("ab", "de");
foreach($excludeKeyword_arr as $exclude){
$filterArray = array_filter($array, function ($var) {return(strpos($var, $exclude) === false);});
}
print_r($filterArray);
It should be return array instead of boolean type.