Hi all! I'm having some trouble figuring out the best way to do the following:
Take a list of names (or nicknames), and properly order them in the following fashion:
symbols -> numbers -> letters
For example:
[Aardvark]
[Banana]
{Andrew
Abe Lincoln
Barbossa
Davey Jones
123 Count
21 Jump Street
If they're in an array (in no specific order), what would be the best way to order them properly? I've got the alpha-numeric order with [man]natsort[/man] down, but that puts all the symbols at the end, and I'd like them at the front. Any ideas?
Currently I have these steps:
-
Query database, order by Name
-
Put result set into array: $nameArray
-
Natural Sort array: $nameArray
-
Reverse array: $nameArray
-
Loop over array with while based on preg_match for specific characters
-
Copy those with symbols as first char to $tmp array
-
Merge the reversal of $tmp and $nameArray together
natsort($orgsArray);
$orgsArray = array_reverse($orgsArray);
$i=0;
$temp = array();
while(preg_match('~^[[{(]+~', substr($orgsArray[$i], 0, 1)) == true)
{
$temp[] = $orgsArray[$i];
unset($orgsArray[$i]);
$i++;
}
$orgsArray = array_merge(array_reverse($temp), array_reverse($orgsArray));
It works, but I was just wondering if there's a faster or better way.