I want to sort bidimensional associative arrays by a given key, using uasort.
I have tried
function sortBy(&$arr, $key) {
$cmp = function($a, $b) {
global $key;
return $a[$key] < $b[$key] ? -1 :
$a[$key] == $b[$key] ? 0 : 1;
};
return uasort($arr, $cmp);
}
But $key is undefined inside $cmp.
function (args) use (variables). Another option is to get object oriented as I answered at this question.