PHP 二位数组排列

// 排列 传入数组 [[1,2],[2,3]]
    public function arranges($d)
    {
        $r = array_pop($d);
        while($d) {
            $t = array();
            $s = array_pop($d);
            if(! is_array($s)) $s = array($s);
            foreach($s as $x) {
                foreach($r as $y) $t[] = array_merge(array($x), is_array($y) ? $y : array($y));
            }
            $r = $t;
        }
        return $r;
    }

结果:
[
[1,2],
[1,3],
[2,2],
[2,3],
]

Posted in