Jump to content

dynamic array multisort


jug
 Share

Recommended Posts

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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.