I\'ve been looking at PHP array permutation / combination questions all day.. and still can\'t figure it out :/
If I have an array like:
20 //key bei
The Idea is simple. Suppose you know how to permute, then if you save these permutations in a set it becomes a combinations. Set by definition takes care of the duplicate values. The Php euqivalent of Set or HashSet is SplObjectStorage and ArrayList is Array. It should not be hard to rewrite. I have an implementation in Java:
public static HashSet> permuteWithoutDuplicate(ArrayList input){
if(input.size()==1){
HashSet> b=new HashSet>();
b.add(input);
return b;
}
HashSet>ret= new HashSet>();
int len=input.size();
for(int i=0;i>temp=permuteWithoutDuplicate(new ArrayList(input));
for(ArrayList t:temp)
t.add(a);
ret.addAll(temp);
input.add(i, a);
}
return ret;
}