On 29 May 2012 18:15, Gary <listgj-phpgeneral@xxxxxxxxxxx> wrote: > Okay, let's assume I have three "things", A, B, and C. I need to produce > an array with a list of all possible combinations of them, however many > there might be in those combinations: e.g. A, B, C, D, AB, AC, AD, BC, > ABC (not sure if I've missed any!). Normally I'm pretty good at working > this stuff out, but to be honest I'm struggling with this one, at least > to do it in any kind of elegant way. Does anyone have any ideas? Sure, but what you are asking for is a permutation and not a combination. Here's a good read on the subject: http://www.mathsisfun.com/combinatorics/combinations-permutations.html Here's the deciding difference: * If the order doesn't matter, then it's a combination. * If the order does matter, then it's a permutation. A combination of ABC is ABC. However, the permutation of ABC is: ABC ACB BAC BCA CAB CBA Oddly enough, a "combination lock" is a misnomer -- it should be a "permutation lock" because the order of the "combination" does matter. In any event, here's the code for as large a permutation as you may want: http://www.webbytedd.com/b1/permutation/ Cheers, tedd _____________________ tedd.sperling@xxxxxxxxx http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php