// Explode to an array$mbrgrp_array = explode(",", $membergroupids); // Add remove/add group to array....code here... // Make it a comma seperated string again$membergroupids = implode(",", $mbrgrp_array);