The following code lays within a function which itself lays within a class. Its purpose is to avoid having one sorting function per $filter value :
$GLOBAL['filter'] = $filter;
usort($this->data, function($arr1, $arr2) {
return ($arr1[$GLOBALS['filter']] > $arr2[$GLOBALS['filter']]) ? 1 : -1;
});
My solution works perfectly fine, but I find it rather inelegant. Would somebody have an idea to acheive the same goal without resorting to the $GLOBALS variable ?
Thanks for your propositions