我需要一个返回所有可能组合的函数,
例如
字符=范围('a','c');
- = aaa
- = aab
- = 阿巴
- = abb
- = abc
- = acb ... n。= cc
(顺序无关紧要)
等等
我懂了
function pc_permute($items, $perms = array( )) {
if (empty($items)) {
$return = array($perms);
} else {
$return = array();
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
$return = array_merge($return, pc_permute($newitems, $newperms));
}
}
return $return;
}
$p = pc_permute(array(0, 1, 2, 3));
var_dump($p);
从这里
但我无法弄清楚如何机会/重写它以获得与多个相同元素的所有可能组合。
谢谢, 穆罕默德