欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php生成数组的使用示例 php全组合算法_PHP

程序员文章站 2024-02-01 14:25:46
...
复制代码 代码如下:
$arr = array(1,2,3,4,5);
/*
@ res 组装好的每一注的每个元素
@ $a 临时数组
@ $index 数组索引
@ $arr 请求的数组
@ $b 最后要的结果
*/
$a = array();
$b = array();
$total = 0;
format($a,0,$arr);
function format($res,$index,$arr){
global $total;
global $b;
$new_arr = $res;
$n_arr = array();
if($index == count($arr)){
if(count($new_arr)==5){
$b[] = $new_arr;
echo "
";
$total++;
}
return;
}
format($new_arr,$index+1,$arr);
$new_arr[] = $arr[$index];
format($new_arr,$index+1,$arr);
}

echo "

";
print_r($b);
echo "
";