All possible combinations, how to make a pattern? PHP?

前端 未结 3 797
情话喂你
情话喂你 2021-01-16 03:04

I\'m doing a code that eliminates unneeded combinations such as I (ABCDE) do not want AAA BBB AB BA only want ABC ABD ABE .... so on, want it to be valid for any situation,

3条回答
  •  鱼传尺愫
    2021-01-16 03:38

    require_once 'Math/Combinatorics.php';
    $combinatorics = new Math_Combinatorics;
    $set = range(1,6);
    $combosWithoutRepetition = $combinatorics->combinations($set, 3);
    foreach ($combosWithoutRepetition as $combo) {
        echo join(',', $combo), "\n";
    }
    

    http://pear.php.net/package/Math_Combinatorics

    you don't need to install pear, you can just download that package and use it.

提交回复
热议问题