OK. A couple of functions with code that might help (if you're interested in copying it instead of rewriting it): in includes/functions.php, function fetch_membergroupids_array() takes the string from the membergroupids field and turns it in to an array (optionally adding in the main groupid, which you wouldn't want to do if you're only updating the secondary groups). Also, in includes/class_dm.php, part of function verify_list() does the opposite - takes the array and makes a comma-separated list.