1

Let's say you have a string like this: 4arb

How can you sort that to become: 4abr

I've already looked at PHP: How to sort the characters in a string? and I know that using sort() would be an option, but I don't see how to incorporate the number part into this.

Ideas?

Community
  • 1
  • 1
gtilflm
  • 1,299
  • 1
  • 19
  • 47
  • 3
    The accepted answer for the question you referred is fully applicable to your case. – Guilherme Sehn Nov 27 '13 at 02:08
  • DOH! I accidentally didn't implement the full solution from the link in my question. Nothing to see here folks... just keep on driving. – gtilflm Nov 27 '13 at 02:16

1 Answers1

1

The solution listed in that will work perfectly. PHP automatically sorts numbers before letters. Use this code

<?php
        $str="a4br1";
        $strarray=str_split($str);
        sort($strarray);
        echo implode("",$strarray); //Returns 14abr
?>
scrblnrd3
  • 6,725
  • 9
  • 32
  • 63