Referencing a method parameter variable from within a sub-function of that method doesn’t seem to work even when global is specified.
public function sortArray(&$array, $keyToCompare){// BOOL sortArray( ARR &$array, STR $keyToCompare )
function cmpVals($pairA, $pairB){
global $keyToCompare;
return strcmp($pairA[$keyToCompare], $pairB[$keyToCompare]);
}
return uasort($array, 'cmpVals');
}
Is it even possible to reference a method parameter from within a sub-function? If so… how?
For my specific example above I realise I could use a closure to achieve the same goal but I don’t want the script to be PHP 5.3 dependent.
Any reason you can’t make it static?