trim($a), explode(",", str_replace(" ", "", $str))); } else { return []; } } function alter_array_contents(array &$a, $add, $remove) { if (($add !== null) && !array_search($add, $a)) { // if user was not assigned to the corresponding group $a[] = $add; } if (($remove !== null) && (($i = array_search($remove, $a)) !== false)) { // only perform deleting if user is assigned to the passed group array_splice($a, $i, 1); } }