array_multisort and dynamic variable options

前端 未结 5 855
孤独总比滥情好
孤独总比滥情好 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:07

    I had the same problem with this answer: "Argument #1 is expected to be an array or a sort flag"

    For anyone having the same problem try this instead:

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

    Note that i have used the reference to my variables "&$" instead of $. This works great in php 5.3 but may cause error in 5.2 due to a bug.

提交回复
热议问题