Alphabetizing Postcodes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lacorp
Forum Newbie
Posts: 4
Joined: Sat Aug 30, 2008 4:24 pm

Alphabetizing Postcodes

Post by lacorp »

Hi,
I need some help alphabetizing an array. The array is full of postcodes from England. When I try to sort() them though I end up with this:
[text]CM0 Southminster
CM1 Chelmsford
CM11 Billericay
CM12 Billericay
CM19 Harlow
CM2 Chelmsford
CM20 Harlow
[/text]

As you can probably guess, this isn't how I want them. I need them sorted numerically as well as alphabetically, so that they'll look like this:
[text]CM0 Southminster
CM1 Chelmsford
CM2 Chelmsford
CM11 Billericay
CM12 Billericay
CM19 Harlow
CM20 Harlow
[/text]
Any help would be greatly appreciated.

Thanks,
lacorp

(Please note that the actual dataset is much larger than what I used as an example)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Alphabetizing Postcodes

Post by AbraCadaver »

Try natsort().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
lacorp
Forum Newbie
Posts: 4
Joined: Sat Aug 30, 2008 4:24 pm

Re: Alphabetizing Postcodes

Post by lacorp »

That solved my problem completely. Thank you so much.
Post Reply