有多個數組. 怎麼計算並獲得有多少種組合??

來源:互聯網
上載者:User
數組A、B、C、D
裡面的個數count不一定都相同。
組合順序是固定的 A[rand] + B[rand] + C[rand] + D[rand] = 不重複字串
怎麼擷取最大的組合數量、不重複字串??


回複討論(解決方案)

本帖最後由 xuzuning 於 2013-10-11 23:59:51 編輯

數量 = count(A) * count(B) * count(C) * count(D)

$a = array('a1', 'a2');$b = array('b1', 'b2');$c = array('c1', 'c2', 'c3');$d = array('d1', 'd2', 'd3');print_r(func($a, $b, $c, $d));function func() {  $d = func_get_args();  $r = array_shift($d);  while($d) {    $t = array();    foreach(array_shift($d) as $x)      foreach($r as $y) $t[] = $y . $x;    $r = $t;  }  return $r;}
Array
(
[0] => a1b1c1d1
[1] => a2b1c1d1
[2] => a1b2c1d1
[3] => a2b2c1d1
[4] => a1b1c2d1
[5] => a2b1c2d1
[6] => a1b2c2d1
[7] => a2b2c2d1
[8] => a1b1c3d1
[9] => a2b1c3d1
[10] => a1b2c3d1
[11] => a2b2c3d1
[12] => a1b1c1d2
[13] => a2b1c1d2
[14] => a1b2c1d2
[15] => a2b2c1d2
[16] => a1b1c2d2
[17] => a2b1c2d2
[18] => a1b2c2d2
[19] => a2b2c2d2
[20] => a1b1c3d2
[21] => a2b1c3d2
[22] => a1b2c3d2
[23] => a2b2c3d2
[24] => a1b1c1d3
[25] => a2b1c1d3
[26] => a1b2c1d3
[27] => a2b2c1d3
[28] => a1b1c2d3
[29] => a2b1c2d3
[30] => a1b2c2d3
[31] => a2b2c2d3
[32] => a1b1c3d3
[33] => a2b1c3d3
[34] => a1b2c3d3
[35] => a2b2c3d3
)

好代碼.解決了.謝謝

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.