/**
* php根据ASCII码表排序特定字符串
* @param $source_str string 原字符
* @param $Symbol string 按什么符号分割字符
* @param string $sort asc|desc 升序或者降序
* @return string
* 例子:sort_string('5,4,3,2,1',','asc')
* 返回结果1,2,3,4,5
*/
function sort_string($source_str,$symbol,$sort='asc'){
$new_str = explode($symbol,$source_str);
if($sort=="desc"){
rsort($new_str);
}else if($sort=="asc"){
sort($new_str);
}
$new_str = implode($symbol,$new_str);
return $new_str;
}
实际开发场景演变出来的需求