You can try:
$test = 'aa,bb,cc,dd,ee'; $match = 'cc'; $output = trim(str_replace(',,', ',', str_replace($match, '', $test), ','));
or
$testArr = explode(',', $test); if(($key = array_search($match, $testArr)) !== false) { unset($testArr[$key]); } $output = implode(',', $testArr);
source share