数组的PHP组合

标签 php testing automated-tests permutation combinations

编辑:这方面的一些背景知识。我们有一个接受 6 个不同变量的模块。我们正在考虑尝试完全自动化测试和微调模块接受的可能的不同值。

我有 6 个数组,需要获得所有可能性的组合。

$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");

所以基本上我正在寻找每一个可能的独特组合,同时仍然保持 $words 数组的顺序。

例子:

C Bb Fq De Bz B1

C Bb Fq De Bz E1

C Bb Fq De Fz B1

最佳答案

这应该会为您提供所需的输出。

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 />";
          }
        }
      }
    }
  }
}

关于数组的PHP组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8752984/

相关文章:

php - 从 session ID 为 0 的购物车中删除项目

javascript - 根据单元格值在 3 种不同的背景颜色之间切换,但前提是另一个调用值不同于

php - date now() 和 MySQL 表内日期的区别

testing - JMeter 加密凭据

testing - 是否可以在不同的先决条件下运行相同的 testcafe fixture

javascript - SELECT Count 从 mysql 到 Google Geo Chart

ruby - 如何使用 watir-webdriver 打开 zip 文件?

javascript - 如何使用 Jest 和 Enzyme 在 React 中测试表单提交?无法读取未定义的属性 'preventDefault'

java - Gradle 忽略 testng 中的优先级

unit-testing - 如何执行 XSLT 样式表的自动化测试?