有一组有序数字,比如$nums = array(3, 7, 10, 12, 20, 24, 26, 34, 37);
我希望从上面的数组获得 6 数字的所有可能组合,而顺序是从最低数字到最大数字;例如:
3, 7, 10, 12, 20, 24
3, 7, 10, 12, 20, 26
3, 7, 10, 12, 20, 34
3, 7, 10, 12, 20, 37
3, 7, 10, 12, 24, 26
3, 7, 10, 12, 24, 34
3, 7, 10, 12, 24, 37
3, 7, 10, 12, 26, 34
3, 7, 10, 12, 26, 37
3, 7, 10, 12, 34, 37
3, 7, 10, 20, 24, 26
3, 7, 10, 20, 24, 34
3, 7, 10, 20, 24, 37
3, 7, 10, 20, 26, 34
3, 7, 10, 20, 26, 37
3, 7, 10, 20, 34, 37
etc...
答案 0 :(得分:0)
听起来你需要计算出数组长度的 factorial ,这样就可以解决这个问题:
function factorial($num){
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
$factorial = $factorial * $x;
}
}
$result = factorial(count($nums));