As I mentioned in the comments, if you have an array, doing implode and then explode using the same delimiter achieves absolutely nothing. In your case $usergroups
will be exactly the same as $temp_array
.
You can greatly simplify your code like this:
// This is just an example using what I think your array contains
$temp_array = array('IT','management','superuser','Marketing');
// Write a list of words to ignore
$ignores = array("management", "Team Leaders", "superuser");
// Loop over your array and remove the entries that contain the ignored words
foreach ($temp_array as $key => $value) {
if (in_array($value, $ignores)) {
unset($temp_array[$key]);
}
}
echo implode(',', $temp_array); // outputs: IT,Marketing