jug Posted October 4, 2010 Share Posted October 4, 2010 Hi, Is there any way to pass dynamic arguments to array_multisort. Below is my idea of what the code should look like. First it has the data then its builds an array of array indexes with the sort direction. This array is then passed to the array_multisort function with the original data. $data[] = array([0] => 67, [1] => 2, [3]' => 2001);$data[] = array([0] => 86, [1] => 4, [3]' => 2002);$data[] = array([0] => 98, [1] => 5, [3]' => 2002);$data[] = array([0] => 86, [1] => 6, [3]' => 2003);$data[] = array([0] => 67, [1] => 1, [3]' => 2004);$arg = array(1 => SORT_ASC, 3 => SORT_DESC);array_multisort($arg, $data); I have got this working with hardcoded values, for example... array_multisort($sort1, SORT_ASC, $sort3, SORT_DESC, $data); but in my code instead of just 2 sorts there could be 'x' amounts. I hope ive made this clear. Any response would be much appreciated. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/215113-dynamic-array-multisort/ Share on other sites More sharing options...
Adam Posted October 4, 2010 Share Posted October 4, 2010 You could use call_user_func_array to pass a dynamic array of parameters to the function. Link to comment https://forums.phpfreaks.com/topic/215113-dynamic-array-multisort/#findComment-1118848 Share on other sites More sharing options...
jug Posted October 4, 2010 Author Share Posted October 4, 2010 thanks for your reply. I did try that too but had no luck. In the end I settled for using eval. Not ideal but does the job. jug Link to comment https://forums.phpfreaks.com/topic/215113-dynamic-array-multisort/#findComment-1118888 Share on other sites More sharing options...
Adam Posted October 4, 2010 Share Posted October 4, 2010 What were you struggling with? If you post your problematic code I'm sure we'll be able to get it working. Link to comment https://forums.phpfreaks.com/topic/215113-dynamic-array-multisort/#findComment-1118903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.