Possible Duplicate:
Sorting an array based on its value
I want to sort an array by a value inside of it. I tried usort
but it leads to some unexpected results in actually changing the value of the output instead of just shifting elements in the array.
Below is the array I want to sort:
Array
(
[element1] => Array
(
[Total] => 1
[paTotal] => 0
[totalPreregistrations] => 7
[totalPreregistrationsToDate] => 26
[pas] => Array
(
[0] => Array
(
[id] => 119
)
)
)
[element2] => Array
(
[Total] => 1
[paTotal] => 0
[totalPreregistrations] => 0
[totalPreregistrationsToDate] => 58
[pas] => Array
(
[0] => Array
(
[id] => 107
)
)
)
... element3, 4, etc...
I want to sort by the "totalPreregistrations" number so that element2 goes above element1 if element2's totalPreregistrations count goes above element1's.
And of course I want the sub-arrays to be retained as well.
Thank you!