PHP: How to sort the characters in a string?

前端 未结 5 1463
傲寒
傲寒 2020-11-30 07:19

I have a set of strings containing characters in a PHP script, I need to sort those characters in each string.

For example:

\"bac\" -> \"abc\"
\"a         


        
5条回答
  •  执念已碎
    2020-11-30 08:20

    You can split the string into an array and then use any of the various sorting functions.

    $in = "this is a test";
    $chars = str_split($in);
    sort($chars);
    $out = implode($chars);
    

提交回复
热议问题