Page 1 of 1

sorting multi dimensional arrays arrayName[int][string]

Posted: Wed Jan 24, 2007 1:53 am
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.

Posted: Wed Jan 24, 2007 2:00 am
by RobertGonzalez
array_multisort().

Or any of the other array sorting functions.