PHP: How to sort the characters in a string?

I would make it an array and use the sort function:

$string = 'bac';

$stringParts = str_split($string);
sort($stringParts);
echo implode($stringParts); // abc

Leave a Comment