0

Firstly, I'm sure this has been answered before, but I can't seem to find it, due to other results that are similar but not quite what I need being the more popular.

Basically I have an array

$array = array('a','b','c','d','e');

I want to get a list of all possible combinations of the array values, but using all of the values exactly once. For example:

abcde acbde edcba etc..

My problem with searching for a solution is that everything shows how to do all combinations using ANY amount of the values, which is not what i want.

Can someone please point me in the right direction; a post that solves for this or how I would go about doing it?

slinkhi
  • 947
  • 4
  • 16
  • 32
  • I believe this has been answered at http://stackoverflow.com/questions/16310553/php-find-all-somewhat-unique-combinations-of-an-array – James Sep 13 '13 at 19:21
  • Search for the `all permutations from array PHP`. It should do the trick. – Nemanja Boric Sep 13 '13 at 19:22
  • [Combinations, dispositions ans permutations in PHP](http://stackoverflow.com/questions/1679605/combinations-dispositions-and-permutations-in-php) – Marty McVry Sep 13 '13 at 19:23
  • Hello all, this is not quite what I need. It gives me ALL of the combinations, including 1-4 element combos. Same with everything else I tried in all these links. Though the accepted answer here http://stackoverflow.com/questions/1256117/algorithm-that-will-take-numbers-or-words-and-find-all-possible-combinations I did not try since i don't have `Math_Combinatorics` installed :( however, I did come up with an idea.. I can just use these and then loop through the results and push only the ones with a `count($array)==5` to a new array, so i got what I needed, thanks! – slinkhi Sep 13 '13 at 19:45
  • @mysql_noobie_xxxx just copy Math_Combinatronics from [here](https://raw.githubusercontent.com/pear/Math_Combinatorics/trunk/Combinatorics.php) it works fine on it's own – Timo Huovinen Jun 24 '14 at 10:05

0 Answers0