dqby43944 2012-01-06 03:21
浏览 27
已采纳

PHP组合的数组

Edit: A little background on this. We have a module that accepts 6 different variables. We are looking at trying to completely automate the testing and fine tuning of the possible different values that the module accepts.

I have 6 arrays and need to get the combinations of all the possibilities.

$words[1] = array("A","B","C","D","E","F");
$words[2] = array("Aa","Bb","Cc","Dd","Ee","Ff");
$words[3] = array("Aq","Bq","Cq","Dq","Eq","Fq");
$words[4] = array("Ab","Bc","Cd","De","Ef","F");
$words[5] = array("Az","Bz","Cz","Dz","Ez","Fz");
$words[6] = array("A1","B1","C1","D1","E1","F1");

So basically I am looking for every possible unique combination, while still maintaining the order of the $words array.

Examples:

C Bb Fq De Bz B1

C Bb Fq De Bz E1

C Bb Fq De Fz B1

  • 写回答

2条回答 默认 最新

  • duanbi7247 2012-01-06 03:48
    关注

    This should give you the desired output.

    for($a=0; $a < count($words[1]); $a++) {
      for($b=0; $b < count($words[2]); $b++) {
        for($c=0; $c < count($words[3]); $c++) {
          for($d=0; $d < count($words[4]); $d++) {
            for($e=0; $e < count($words[5]); $e++) {
              for($f=0; $f < count($words[6]); $f++) {
                echo $words[1][$a] . " " . $words[2][$b] . " " . $words[3][$c] . " " . $words[4][$d] . " " . $words[5][$e] . " " . $words[6][$f] . "<br />";
              }
            }
          }
        }
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c