我如何取一个字符串并订购它的字母

时间:2012-01-01 03:32:20

标签: php string

如果我有一个字符串flags,我如何确保其字母按字母顺序排序,在这种情况下是afgls

2 个答案:

答案 0 :(得分:4)

您可以使用str_split()sort()implode()执行此操作:

$arr = str_split($str)
sort($arr, SORT_STRING);
$str = implode($arr);

答案 1 :(得分:0)

编辑使用字符串拆分功能而不是爆炸

您可能希望使用str_split函数:http://us.php.net/str_split

以及数组排序功能:http://php.net/manual/en/function.sort.php

最后,Implode函数:http://php.net/manual/en/function.implode.php

相关问题