Sorting Arrays by More the One Value, and Prioritizing the Sort based on Column data.

Posted by Mark Tomlin on Stack Overflow See other posts from Stack Overflow or by Mark Tomlin
Published on 2010-03-08T02:08:17Z Indexed on 2010/03/08 4:36 UTC
Read the original article Hit count: 384

Filed under:
|
|

I'm looking for a way to sort an array, based on the information in each row, based on the information in certain cells, that I'll call columns.

Each row has columns that must be sorted based on the priority of: timetime, lapcount & timestamp.

Each column cotains this information: split1, split2, split3, laptime, lapcount, timestamp.

laptime if in hundredths of a second. (1:23.45 or 1 Minute, 23 Seconds & 45 Hundredths is 8345.) Lapcount is a simple unsigned tiny int, or unsigned char. timestamp is unix epoch.

The lowest laptime should be at the get a better standing in this sort. Should two peoples laptimes equal, then timestamp will be used to give the better standing in this sort. Should two peoples timestamp equal, then the person with less of a lapcount get's the better standing in this sort.

By better standing, I mean closer to the top of the array, closer to the index of zero where it a numerical array.

I think the array sorting functions built into php can do this with a callback, I was wondering what the best approch was for a weighted sort like this would be.

© Stack Overflow or respective owner

Sorting Arrays by More the One Value, and Prioritizing the Sort based on Column data.

Posted by Mark Tomlin on Stack Overflow See other posts from Stack Overflow or by Mark Tomlin
Published on 2010-03-08T02:08:17Z Indexed on 2010/03/08 2:12 UTC
Read the original article Hit count: 384

Filed under:
|
|

I'm looking for a way to sort an array (we call this a row), with an array of values (that I'll call columns).

Each row has columns that must be sorted based on the priority of: timetime, lapcount & timestamp.

Each column cotains this information: split1, split2, split3, laptime, lapcount, timestamp.

laptime if in hundredths of a second. (1:23.45 or 1 Minute, 23 Seconds & 45 Hundredths is 8345.) Lapcount is a simple unsigned tiny int, or unsigned char. timestamp is unix epoch.

The lowest laptime should be at the get a better standing in this sort. Should two peoples laptimes equal, then timestamp will be used to give the better standing in this sort. Should two peoples timestamp equal, then the person with less of a lapcount get's the better standing in this sort.

By better standing, I mean closer to the top of the array, closer to the index of zero where it a numerical array.

I think the array sorting functions built into php can do this with a callback, I was wondering what the best approch was for a weighted sort like this would be.

© Stack Overflow or respective owner

Related posts about php

Related posts about sort