sorting multi dimensional arrays arrayName[int][string]

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
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

sorting multi dimensional arrays arrayName[int][string]

Post by Stephen Bungert »

I have a multidimensional array

The first array is indexed, the sub arrays are named

I can see how to sort indexed arrays but how on earth do I sort the arrays, based on the value of string:

Code: Select all

arrayName[index][string]
I want to sort by date based on the value in

Code: Select all

newTermineItems[0]["datum"]
so for example (just displaying to elements and just one named sub element)

Code: Select all

newTermineItems[0]["datum"] = "7.12.04";
newTermineItems[1]["datum"] = "5.12.04";
after sorting, the array looks like:

Code: Select all

newTermineItems[0]["datum"] = "5.12.04";
newTermineItems[1]["datum"] = "7.12.04";

I turned the datum string in to a unix time stamp in case some users provide dates in other formats, I tested sorting timestamps and this worked great, on a single dim. array. How do I do this on a multi dim array? I need to move the whole

Code: Select all

newTermineItems[0]
index and not just the value in

Code: Select all

newTermineItems[0]["datum"]
as the sub arrays have several named indexes.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

array_multisort().

Or any of the other array sorting functions.
Post Reply