Sorting complex arrays
Posted: Sun Apr 30, 2006 1:47 pm
Having never dealt with any of the array sorting functions I assume they are mostly for sorting simple, single-dimension arrays???
Anyways, here is my problem I am hoping can be solved using built-in functionality as opposed to me writting all the sorting code by hand
I have any array which looks like this:
The array name is $arr_test for the sake of this disscussion...
Is there a way I can specify which column I want sorted using builtin array functions?
Heres the catch...if I sort by time in ascending order...I need the parent array indicies to change as well, so sorting the above array would return the same as above...but descending
would become index ONE...
It appears as though I will need to write this manually from what I can tell by quickly glancing at the array sorting functions, they would just sort the columns and NOT reorder the parent array indicies, thus jumbling the data..???
Cheers
Anyways, here is my problem I am hoping can be solved using built-in functionality as opposed to me writting all the sorting code by hand
I have any array which looks like this:
Code: Select all
Array
(
[0] => Array
(
[fname] => George
[lname] => Lucas
[time] => 1
)
[1] => Array
(
[fname] => Alexander
[lname] => Gallagher
[time] => 2
)
[2] => Array
(
[fname] => Matthew
[lname] => Black
[time] => 3
)
)Is there a way I can specify which column I want sorted using builtin array functions?
Heres the catch...if I sort by time in ascending order...I need the parent array indicies to change as well, so sorting the above array would return the same as above...but descending
Code: Select all
Matthew, Black, 3would become index ONE...
It appears as though I will need to write this manually from what I can tell by quickly glancing at the array sorting functions, they would just sort the columns and NOT reorder the parent array indicies, thus jumbling the data..???
Cheers