## 求个递归的代码。折磨一天了！！！

```\$a = [1,2,3,4]
//\$a数组要求重新生成长度为2，3...N的新数组
//规律如下：
//长度为2的
\$b = [
[1,2]
[1,3]
[1,4]
[2,3]
[2,4]
[3,4]
]
//长度为3的
\$b = [
[1,2,3]
[1,2,4]
[2,3,4]
]
\$a = [1,2,3,4,5,6]
//长度为4的新数组
\$b = [
[1,2,3,4]
[1,2,3,5]
[1,2,3,6]
[2,3,4,5]
[2,3,4,6]
[2,3,5,6]
[3,4,5,6]
]```

0

```<?php

\$a = array(1, 2, 3, 4);

\$c = new CuteArray();

\$c->cut(\$a, 1);

print_r(\$c->get());

class CuteArray {

private \$b = array();
private \$n = 0;

function cut(\$a, \$length) {
if (count(\$a) <= \$length) {
return;
}
\$b = array();
for (\$i = 0; \$i < \$length; \$i++) {
\$b[\$i] = \$a[\$i];
}
for (\$i = \$length; \$i < count(\$a); \$i++) {
\$b[\$length] = \$a[\$i];
\$this->b[\$this->n] = \$b;
\$this->n++;
}
array_shift(\$a);
\$this->cut(\$a, \$length);
}

function get() {
return \$this->b;
}

}```

0

0

[1,2,3,4]

[1,2,3,5]
[1,2,3,6]
[2,3,4,5]
[2,3,4,6]
[2,3,5,6]
[3,4,5,6]

0

```<?php
function combinations(\$list, \$size, \$from = 0, \$buffer = array()) {
\$result = array();
if (\$size <= 0) {
array_push(\$result, \$buffer);
} else {
\$length = count(\$list);
for (\$i = \$from; \$i <= \$length - \$size; \$i++) {
array_push(\$buffer, \$list[\$i]);
\$result = array_merge(\$result, combinations(\$list, \$size - 1, \$i + 1, \$buffer));
array_pop(\$buffer);
}
}
return \$result;
}

\$result = combinations(array(1, 2, 3, 4, 5), 3);
print_r(\$result);```

0

php没用过，写了个python版的，你就看看递归的思路吧

```a = [1, 2, 3, 4, 5, 6]

def cut(array, num):
if (len(array) <= num):
print(array)
return

tmp = num-1
while tmp <= (len(array)-1):
reslut = array[0:(num-1)]
reslut.append(array[tmp])
print(reslut)
tmp=tmp+1

cut(array[1:], num)

cut(a, 4)```

```[1, 2, 3, 4]
[1, 2, 3, 5]
[1, 2, 3, 6]
[2, 3, 4, 5]
[2, 3, 4, 6]
[3, 4, 5, 6]```

0
http://my.oschina.net/u/189899/blog/296451
0

```var note2 = function(\$arr,\$n,\$result)
{
var \$len = \$arr.length;
var \$ret = [];
for(var \$i = 0;\$i<\$len;\$i++)
{
\$result = \$result.concat([\$arr[\$i]]);
var \$temp = [].concat(\$arr);
for(var i=0;i<=\$i;i++)
{
\$temp.shift()
}
if(\$result.length == \$n)
{
\$ret[\$ret.length] = [].concat(\$result);
} else {
\$tmp = note2(\$temp,\$n,\$result);
for(var it=0;it<\$tmp.length;it++)
{
\$ret[\$ret.length] = [].concat(\$tmp[it]);
}
}
\$result.pop();
}
return \$ret;
}
\$a = [1,2,3,4,5,6,7,8,9,10,11]
\$n = 2;
\$t = note2(\$a,\$n,[]);
console.log(\$t.length)
console.log(\$t)```