array_multisort and dynamic variable options

前端 未结 5 856
孤独总比滥情好
孤独总比滥情好 2020-11-27 08:53

Im trying to sort any array with array_multisort and everything is working great. However, based on conditions in my script, I need to change the options. So What I have s

5条回答
  •  我在风中等你
    2020-11-27 09:03

    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)
    

提交回复
热议问题