PHP:如何排序字符串中的字符? [英] PHP: How to sort the characters in a string?
本文介绍了PHP:如何排序字符串中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组包含PHP脚本中字符的字符串,我需要在每个字符串中排序这些字符。
I have a set of strings containing characters in a PHP script, I need to sort those characters in each string.
例如:
"bac" -> "abc"
"abc" -> "abc"
"" -> ""
"poeh" -> "ehop"
这些字符没有重音符,都是小写。
These characters don't have accents and are all lower case. How can I perform this in PHP?
推荐答案
我会使它成为一个数组并使用sort函数:
I would make it an array and use the sort function:
$string = 'bac';
$stringParts = str_split($string);
sort($stringParts);
echo implode('', $stringParts); // abc
这篇关于PHP:如何排序字符串中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文