不确定您需要什么,但您是否正在尝试产生这些排列?
这应该可以帮助您入门,它将对您需要的任何大小的集合执行完全排列。加了一些注解,应该能明白
$array = array('A','B','C', 'D');
$permutations = array($array);
$perm_pool = range(0, count($array)-1);
function getPermutation($p, $size){
// we pass in an array of integers, basically pointers, we want to see when we've fully reversed the set
for ($i = $size-1; $p[$i] >= $p[$i+1]; $i--){}
// the array starts at [1,2,3,4], when we've reached [4,3,2,1], we're done.
if ($i == -1) { return false; }
// slide down to the next largest number, this will be our next swap
for ($j = $size; $p[$j] <= $p[$i]; $j--) {}
// swap it
$tmp = $p[$i];
$p[$i] = $p[$j];
$p[$j] = $tmp;
// reverse the arrangement by swapping the head and tails
for ($i++, $j = $size; $i < $j; $i++, $j--){
$tmp = $p[$i];
$p[$i] = $p[$j];
$p[$j] = $tmp;
}
return $p;
}
$i=1;
while($perm_pool=getPermutation($perm_pool, count($array)-1)){
foreach($perm_pool as $p){
$permutations[$i][] = $array[$p];
}
$i++;
}