Sort array using array_multisort() with dynamic number of arguments/parameters/rules/data

You could try to use call_user_func_array. But I’ve never tried it on a built-in function before. Here is an example:

$dynamicSort = "$sort1,SORT_ASC,$sort2,SORT_ASC,$sort3,SORT_ASC";
$param = array_merge(explode(",", $dynamicSort), array($arrayToSort))
call_user_func_array('array_multisort', $param)

Leave a Comment