Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multidimensional array sort - can it be done?

Status
Not open for further replies.

mhamilton3

Programmer
Oct 31, 2001
129
I have an array ($a) that appears as follows:

john 10 01/01/1950 builder
tony 31 01/01/1997 plumber
mark 15 10/15/1975 captain
adam 18 11/27/1961 driver

and I want to sort it by any column. For simplicity's sake, let's say the last one. I can't find a simple process. Does one exist? The row has to be maintained (tony stays with 31, 01/01/1997, and plumber).

Any help would be appreciated. Thanks.
 
Well, what about this:

Join (with implode) each array into a string beginning with the column you want to sort on:

plumber#tony#31#01/01/1997
.
.
.

You'll now have an array of strings. Sort it and the split it using explode.

There are other ways too.
 
Where there is a will, there is a way, thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top