this is driving me mad... I've read the manual and looked at a few posts on this site as well as through goole, and I cannot get my head around sorting an array with the following data:
Array
(
[0] => Array
(
[hierarchy] => 6
[metricID] => V20102
)
[1] => Array
(
[hierarchy] => 7
[metricID] => R20109
)
[2] => Array
(
[hierarchy] => 8
[metricID] => R20106
)
[3] => Array
(
[hierarchy] => 5
[metricID] => R20110
)
[4] => Array
(
[hierarchy] => 4
[metricID] => C20100
)
[5] => Array
(
[hierarchy] => 1
[metricID] => C20104
)
[6] => Array
(
[hierarchy] => 3
[metricID] => C20119
)
[7] => Array
(
[hierarchy] => 2
[metricID] => C20140
)
)
I need to sort them by the "hierarchy" number. I've got the following code which doesnt seem to do anything... probably I am not using it correctly!?
usort($my_array, "cmp");
function cmp($a, $b) {
if ($a['hierarchy'] == $b['hierarchy']) return 0;
return ($a['hierarchy'] < $b['hierarchy']) ? -1 : 1;
}
any help will be much appreciated!!