I have a multidimensional array and I would like to sort it so that both arrays are sorted by the flag SORT_NATURAL
and then either SORT_ASC
or SORT_DESC
So from what I understand it should look like this:
array_multisort($array1, SORT_NATURAL, SORT_ASC, $array2, SORT_NATURAL, SORT_ASC, $array);
But it seems to only be applying the SORT_NATURAL
to the $array1
and the $array2
is not sorted at all, not even the sort direction is applied.
But as soon as I remove the SORT_NATURAL
form $array2
, the sort direction works.
So- $array1
sorts perfectly fine, but $array2
does not sort at all.
What could be the problem? Am I missing something?
public function sortMultiDimensional(&$array, $subKey, $subKey2, $sortorder_packing_bool=false, $sortorder_packing_secondary_bool=false) {
$array1 = array();
$array2 = array();
foreach ($array as $key => $row) {
$array1[$key] = $row[$subKey];
$array2[$key] = $row[$subKey2];
}
if($sortorder_packing_bool)
$sortorder_packing_bool = SORT_ASC;
else
$sortorder_packing_bool = SORT_DESC;
if($sortorder_packing_secondary_bool)
$sortorder_packing_secondary_bool = SORT_ASC;
else
$sortorder_packing_secondary_bool = SORT_DESC;
array_multisort($array1, $sortorder_packing_bool, SORT_NATURAL, $array2, $sortorder_packing_secondary_bool, SORT_NATURAL, $array);
}