这里我有一个代码,给了我所需的输出,但我想在选择时添加优先顺序
所有可能的组合代码
$array = array('x2', 'y', 'm');
function depth_picker($arr, $temp_string, &$collect) {
if ($temp_string != "")
$collect []= $temp_string;
for ($i=0; $i<sizeof($arr);$i++) {
$arrcopy = $arr;
$elem = array_splice($arrcopy, $i, 1); // removes and returns the ith element
if (sizeof($arrcopy) > 0) {
depth_picker($arrcopy, $temp_string ." " . $elem[0], $collect);
} else {
$collect []= $temp_string. " " . $elem[0];
}
}
}
$collect = array();
depth_picker($array, "", $collect);
print_r($collect);
我找到了这段代码,但我无法加入
function array_permutation(array $array)
{
$count = array_map('count', $array);
$finalSize = array_product($count);
$arraySize = count($array);
$output = array_fill(0, $finalSize, []);
$i = 0;
$c = 0;
for (; $i < $finalSize; $i++) {
for ($c = 0; $c < $arraySize; $c++) {
print $output[$i][] = $array[$c][$i % $count[$c]];
}
print "<br/>";
}
return $output;
}
$array = [['x2','x1'], ['y','k'], ['m', 'n']];
//print $output;
$output= array_permutation($array);
我正在寻找将脚本输出为
x2
x1
y
k
m
n
x2y
x1y
x2k
x1k
x2ym
x1ym
x2yn
x1yn
x2km
x1km
x2kn
x1kn
...同样