How would you remove common words (the, is, a, as) from the the English language in PHP from an array?
Example of an array could be
$story = array("Jack", "is", "going", "out", "to", "play");
How would you remove common words (the, is, a, as) from the the English language in PHP from an array?
Example of an array could be
$story = array("Jack", "is", "going", "out", "to", "play");
If you need to preserve the content of the array and have it empty if you replace everything in every element...
$common = ["the", "as", "is", "a"];
foreach($array as &$element) {
$element = str_replace($common, "", $element);
}
This should work. Let's say you have your content in $array
, we are looping on it and remove from each element the content of $common
which you can customize as you need.
Otherwise, if you have to "pop" the element ("pop" for "remove completely")...
foreach ($array as $k => $v) {
if (in_array($v, $common)){
unset($array[$k])
}
}