Sort an Array into arbitrary columns
Posted: Thu Jun 03, 2004 9:08 am
Lets say I define a table as having 2 columns.
I have an array of 35 names which I want to display in alphabetical order such that:
Now I now how to display an arbitrary number of columns and I've written a function which will produce each row for a given number of columns and complete the last row with any necessary empty cells.
The difficulty I have is in sorting the array so that values appear in the right order.
After sorting alphabetically I need to break up the array into 2 columns like a card dealer would mix a deck of cards.
For future re-use purposes the function would do the same for any number of columns so if I changed the table layout from 2 to 3 cols then the function should make three lists when iterated through.
Seems like a good candidate for an already existing array function but I'm not certain if something exists and nothing screams at me as being obvious when looking through the manual.
I know I could break the information into 2 tables but then the rows wouldn't necessarily line up so this is not an option.
Well, is there a quick way of doing this with existing functions?
I have an array of 35 names which I want to display in alphabetical order such that:
Code: Select all
<tr><td>$arrayї0]</td><td>$arrayї18]</td></tr>
<tr><td>$arrayї1]</td><td>$arrayї19]</td></tr>
...
<tr><td>$arrayї17]</td><td> </td></tr>The difficulty I have is in sorting the array so that values appear in the right order.
After sorting alphabetically I need to break up the array into 2 columns like a card dealer would mix a deck of cards.
For future re-use purposes the function would do the same for any number of columns so if I changed the table layout from 2 to 3 cols then the function should make three lists when iterated through.
Seems like a good candidate for an already existing array function but I'm not certain if something exists and nothing screams at me as being obvious when looking through the manual.
I know I could break the information into 2 tables but then the rows wouldn't necessarily line up so this is not an option.
Well, is there a quick way of doing this with existing functions?