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.
Try adding
use, which passes variables from the outer scope to anonymous functions