Ok, I figured it out.....FINALLY!!
My code was almost correct.....$sortarr changed a little bit, but the real problem is that the array arguments to array_multisort() MUST be passed by reference in order for this to work!!
Instead of this:
foreach ($arr as $a) {
$keys = array_keys($a);
$sortarr[][$keys[$column]] = $a[$keys[$column]];
}
array_multisort($sortarr, $sortoder, $arr, $sortorder);
Do this:
foreach ($arr as $a) {
$keys = array_keys($a);
$sortarr[] = $a[$keys[$column]];
}
array_multisort(&$sortarr, $sortoder, &$arr, $sortorder);
Gotta love those user-contributed notes in the PHP manual....
if you're having problems with array_multisort changing variables in global space when it is called inside a function and you're not passing in the function parameters by reference you can alleviate the problem by calling array_multisort with its parameters by reference, eg, array_multisort(&$a, SORT_DESC, &$b);
So here is a general function to handle multi-dimensional array sorting by a specific column and order:
function array_csort(&$arr, $column=0, $order='asc') {
$order = ($order == 'asc') ? SORT_ASC : SORT_DESC;
foreach ($arr as $a) {
$keys = array_keys($a);
$sortarr[] = $a[$keys[$column]];
}
array_multisort(&$sortarr, $order, &$arr, $order);
} // array_csort