Remove elements of one array if it is found in another [duplicate]
Solution 1:
You are looking for array_diff
:
$subject = "Warmly little in before cousin as sussex...";
$tags = explode(" ", strtolower($subject));
$definite_articles = array('the','this','then','there','from','for','to','as');
$tags = array_diff($tags, $definite_articles);
print_r($tags);
See it in action.
Solution 2:
Sounds like an easy job for array_diff()
.
array array_diff ( array $array1 , array $array2 [, array $... ] )
Compares
array1
againstarray2
and returns the difference.
Which basically means it will return array1
after it's been stripped of all values which exist in array2
.