I'm writing customized sort function. Current (non-working) code looks like this:
<?php
function sort_by_key($array, $key) {
function custom_compare ($a, $b) {
if ($a[$key][0] > $b[$key][0]) { return 1; }
else { return -1; }
}
return usort($array, "custom_compare");
}
?>
The problem is that I cannot pass $key variable to custom_compare function. I'd like to avoid using global variables (ugly coding).