Mido Posted August 2, 2010 Share Posted August 2, 2010 How can I sort a string alphabetically? I thought about creating an array ('a'=>0, 'b'=>1) etc, but didn't manage to work. So how can I do this? is there a predefined function for this? or I should create the algorithm? Thanks, Example: $word = 'cbad432'; // should become: '234abcd' Quote Link to comment https://forums.phpfreaks.com/topic/209565-alphabetizing-a-word/ Share on other sites More sharing options...
bh Posted August 2, 2010 Share Posted August 2, 2010 Hi, E.g. try to use the ord function to get the ASCII value of a character. Quote Link to comment https://forums.phpfreaks.com/topic/209565-alphabetizing-a-word/#findComment-1094046 Share on other sites More sharing options...
JonnoTheDev Posted August 2, 2010 Share Posted August 2, 2010 You were on the right lines. <?php $word = str_split('cbad432'); sort($word); $word = implode($word); print $word; ?> Quote Link to comment https://forums.phpfreaks.com/topic/209565-alphabetizing-a-word/#findComment-1094077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.