1

我有这个数组

$dataArray = array
        (
        array(1,11,111),
        array(2,22,222),
        array(3,33,333),
        array(4,44,444)
    );

我也用谷歌搜索,但没有PHP找到有用的脚本..

使用置换组合方法的结果

1,11,111
1,111,11
11,111
1,11,
2,11,111
2,11,1
.
.
.
.

是的,我已经用排列组合方法尝试过

function permutations(array $array, $r=false)
    {
        switch (count($array)) {
            case 1:
                return $array[0];
                break;
        }

        $keys = array_keys($array);

        $a = array_shift($array);
        $k = array_shift($keys); // Get the key that $a had
        $b = permutations($array, 'recursing');

        $return = array();
        foreach ($a as $v) {
            if($v)
            {
                foreach ($b as $v2) {
                    if($r == 'recursing')
                        $return[] = array_merge(array($v), (array) $v2);
                    else
                        $return[] = array($k => $v) + array_combine($keys, $v2);
                }
            }
        }

    return $return;
}


$x = permutations($dataArray);      
echo "<pre>";               
print_r($x);
4

0 回答 0