Well - I solved my problem now, but I will post here what it was if it helps other people
Structure of array:
Array (
[0] => Array ( [cust_id] => 307 [inv_date] => 1020853454 [name] => Fred )
[1] => Array ( [cust_id] => 1 [inv_date] => 1020851903 [name] => Bob )
[2] => Array ( [cust_id] => 358 [inv_date] => 1029325324 [name] => Willy )
[3] => Array ( [cust_id] => 18 [inv_date] => 1025022376 [name] => Tom )
)
My array had heaps more keys in it, but this is a simplified version. I wanted to sort all the array around based on a user-defined key.
eg: if the user wants it sorted by the name, the array after the sort should be:
Array (
[0] => Array ( [cust_id] => 1 [inv_date] => 1020853454 [name] => Bob )
[1] => Array ( [cust_id] => 307 [inv_date] => 1020851903 [name] => Fred )
[2] => Array ( [cust_id] => 18 [inv_date] => 1025022376 [name] => Tom )
[3] => Array ( [cust_id] => 358 [inv_date] => 1029325324 [name] => Willy )
)
the code I ended up using is:
function sorter ($a, $b) {
global $sort_by;
global $order_by;
$a_str = $a[$sort_by] . $a['inv_date'] . $a['name'];
$b_str = $b[$sort_by] . $b['inv_date'] . $b['name'];
if ($order_by) {
return strcasecmp($b_str, $a_str);
} else {
return strcasecmp($a_str, $b_str);
}
}
uasort ($match_inv, "sorter");