We help IT Professionals succeed at work.
Get Started

how do I get all combinations of a set of constants?

Lennart Ericson
Last Modified: 2013-12-13
Suppose we have six constants: 1 through 6.

I would like to have a formula to get all combinations of of them,

I give an example of what I mean:

1 and 2 and 3 and 4 and 5 and 6
1 and 2 and 3 and 4 and 5, but not 6
1 and 2 and 3 and 4, but not 5 and 6
2 and 3 and 4 and 5 and 6, but not 1
3 and 4 and 5 and 6, but not 1 and 2
1 and 3 and 4 and 5 and 6, but not 2
1 and 4 and 5 and 6, but not 2 and 3
I Think you've got it.

Lastly, I'd put this in a php script to get the correct combination

if(1 and 2 and 3 and 4 and 5 and 6) {  do this  }
if(1 and 2 and 3 and 4 and 5)  {  do that  }

For me this is far over my training. Could you please lead me thorugh this.

Watch Question
Most Valuable Expert 2014
Top Expert 2015
This problem has been solved!
Unlock 5 Answers and 11 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE