I have a multidimensional array called $arrActivities.
In order to use php's array_multisort, I have created four arrays: $arrField0,$arrField1, $arrField2 and $arrField3, which are all arrays of specific fields found in $arrActivities.
Using those arrays, this command works perfectly:
array_multisort($arrField0, SORT_STRING, $arrField1, SORT_STRING, $arrField2, SORT_STRING, $arrField3, SORT_STRING, $arrActivities);
I need to create that parameter string dynamically, though, as sometimes there may be five arrays depending on the dataset.
I tried dynamically creating a string:
$strSort = '$arrField0, SORT_STRING, $arrField1, SORT_STRING, $arrField2, SORT_STRING, $arrField3, SORT_STRING, $arrActivities';
This works (ie it does the sorting correctly) but I get a warning:
array_multisort($strSort);
Warning: array_multisort(): Argument #1 is expected to be an array or a sort flag
What is the right way to pass in the arguments with a string or array where I don't get a warning?
Why do I get the warning but it sorts correctly?
SOLUTION:
I found the solution of building a dynamic list of parameters for array_multisort by using call_user_func_array:
I am able to produce the $arrSort array dynamically and it sorts correctly without an error or warning.