I'm having a bit of trouble sorting an array by sub-sub array values. I've tried some things like usort but it doesn't seem to work. I have a multidimensional array called $array_1 which is made dynamicly based on search criteria (for instance a deadline date, priority number, group number etc.) which creates a subarray per value that is the same. i.e. it'll make a sub-array for all the sub-sub arrays that have group->1, another sub-array for group->2. Now I want to sort the sub-arrays by for instance date, which should keep the sub-arrays clustered by group(1 and 2).
edit: I'm now using an array sorting function and I think the problem is as follows: I can use values but not variables in the following function:
foreach($array_1 as &$arr){
usort($arr,"cmp");
}
function cmp($a, $b) {
if ($a[2] == $b[2]) {
return 0;
}
return ($a[2] < $b[2]) ? -1 : 1;
}
echo $type;
print_r($array_1);
if I replace the number 2 with a variable which is also 2 and have check with is_numeric the function doesn't work. Why is this?