Page 1 of 1

Getting all possible order variations of array

Posted: Thu Mar 13, 2008 1:08 pm
by nutkenz
Is there an existing function or can someone think of a good way to get all possible variations of the order of elements in an array? By this I mean, if I had an array like this:

Code: Select all

array(1,2,3,4);
I would run it through the function and get:

Code: Select all

array(
   array(1,2,3,4);
   array(1,3,2,4);
   array(1,3,4,2);
   array(1,4,2,3);
   array(1,4,3,2);
   array(2,3,4,1);
   ...
)

Re: Getting all possible order variations of array

Posted: Thu Mar 13, 2008 1:22 pm
by hawleyjr
This can be done with a recursive loop.

Re: Getting all possible order variations of array

Posted: Thu Mar 13, 2008 1:37 pm
by nutkenz
hawleyjr wrote:This can be done with a recursive loop.
Could you into a bit more detail? Also, would this be the most resource-friendly solution?