3d array sorting
| From: | Charles Killian | Date: | Tue, 25 Jul 2000 18:21:17 +0000 |
| Subject: | 3d array sorting | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-8111@lists.php.net to get a copy of this message | ||
I'm trying to sort a three dimensional array but I need help.
Here's the setup:
I'm parsing an xml document into an array and then automatically outputting the data into a
table. I dynamically decide how many columns and rows are in the table depending on the data loaded
from the xml document.
I'm storing a row using the first array index:
$ar[0]
I'm storing the column using the second array index:
$ar[0][0]
I'm storing the specific contents of the column associative third index:
$ar[0][0]["value"]
I end up with something like this:
# row 0, column 0
$ar[0][0]["value"]="00value";
$ar[0][0]["href"]="00href";
$ar[0][0]["nowrap"]="00nowrap";
#row 0, column 1
$ar[0][1]["value"]="01value";
$ar[0][1]["href"]="01href";
$ar[0][1]["nowrap"]="01nowrap";
# row 1, column 0
$ar[1][0]["value"]="10value";
$ar[1][0]["href"]="10href";
$ar[1][0]["nowrap"]="10nowrap";
# row 1, column 1
$ar[1][1]["value"]="11value";
$ar[1][1]["href"]="11href";
$ar[1][1]["nowrap"]="11nowrap";
# row 2, column 0
$ar[2][0]["value"]="20value";
$ar[2][0]["href"]="20href";
$ar[2][0]["nowrap"]="20nowrap";
# row 2, column 1
$ar[2][1]["value"]="21value";
$ar[2][1]["href"]="21href";
$ar[2][1]["nowrap"]="21nowrap";
I can output a table with ease using this array structure.
Here's the hitch: HOW DO I SORT THE ARRAY KEEPING THE ROW-COLUMNS TOGETHER BUT SORTING ON A
SPECIFIC COLUMN ["value"]?
I want to be able to click on the table heading and sort by the heading just like in a Mail program,
click on received and the messages are sorted by date received.
I repeat, I won't know how rows or columns are in my array until the data is loaded from the
xml document.
Is there a better way to perform this table sorting? data gathering?
I'd appreciate any help.
Charles