I am using php function usort to sort an array. The custom php function must be generated because its dynamic
$intCompareField = 2;
$functSort = function($a, $b) {
return ($a[$intCompareField] > $a[$intCompareField])?1:-1;
}
usort($arrayToSort, $functSort);
The $intCompareField in the compare function is null, my guessing is because the $intCompareField was declared outside of the function. Setting global $intCompareField does not seem to work.
Ps: I am using $intCompareField because the array to sort is multidimensional and i want to be able what key in the array to sort.
1or-1, it is generally desired to return0for "equal" values.