字符串 0304,0304,0305,0305,0305,0305,0302,0304,0305,0302,0301,将相同的值去掉只留一个并排序
$str = "0304,0304,0305,0305,0305,0305,0302,0304,0305,0302,0301";
echo $str;
//将字符串转化成数组
$array = explode(",",$str);
echo "<pre>";
print_r($array);
//去掉数组中重复值
$result = array_unique($array);
print_r($result);
//从小到大排序
asort($result);
print_r($result);
//索引重排序
$result=array_values($result);
print_r($result);
//将数组转化成字符串
$array_num = count($result);
$str = '';
for($i=0;$i<$array_num;$i++){
$str.=$result[$i].",";
}
$str = substr($str, 0, -1);
echo $str;
结果: