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

2025-05-29 0 13

复制代码 代码如下:


<?php
$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 "<pre>";
$total++;
}
return;
}
format($new_arr,$index+1,$arr);
$new_arr[] = $arr[$index];
format($new_arr,$index+1,$arr);
}

echo "<pre>";
print_r($b);
echo "</pre>";

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 php生成数组的使用示例 php全组合算法 https://www.kuaiidc.com/105408.html

相关文章

发表评论
暂无评论