这是因为array_unique()将重复项减少到一个值:接受一个输入数组并返回一个没有重复值的新数组。源代码您需要先循环数组(尽管可以想象很多有创意的 array_filter/array_walk 东西):$string = 'Super this is a test this is a test';# first explode it$arr = explode(' ', $string);# get value count as var$vals = array_count_values($arr);foreach ($arr as $key => $word){ # if count of word > 1, remove it if ($vals[$word] > 1) { unset($arr[$key]); }}# glue whats left togetherecho implode(' ', $arr);小提琴作为一般项目使用的功能:function rm_str_dupes(string $string, string $explodeDelimiter = '', string $implodeDelimiter = ''){ $arr = explode($explodeDelimiter, $string); $wordCount = array_count_values($arr); foreach ($arr as $key => $word) { if ($wordCount[$word] > 1) { unset($arr[$key]); } } return implode($implodeDelimiter, $arr);}# example usageecho rm_str_dupes('Super this is a test this is a test');