0

以下のすべての可能な組み合わせをリストする方法:

文字列 (4 文字、数字または特殊記号なしの小文字のみ)、# 記号、文字列 (5 文字、1 番目と同じルール)。

例えば:

dhgi#msodd

4

2 に答える 2

6

前提:英語のアルファベット

for($firstPart = 'aaaa'; $firstPart != 'aaaaa'; $firstPart++) {
   for($secondPart = 'aaaaa'; $secondPart != 'aaaaaa'; $secondPart++) {
      echo $firstPart,'#',$secondPart,'<br />';
   }
}

なぜあなたがこれをしたいのか、私にはわかりません。

これはあなたの前の質問に関連していますか?

于 2011-02-03T14:37:05.227 に答える
0

再帰を利用

  function bruteforce($data)
{
    $storage = array();
    tryCombination($data,'',$storage);
    return $storage;
}


function tryCombination($input,$output,&$storage)
{
    if($input == "")
    {

        if(!in_array($output,$storage))
        array_push($storage,$output);

    }else {
        for($i = 0 ; $i < strlen($input) ; $i++)
        {
            $next = $output  . $input[$i];
            $remaining = substr($input,0,$i)  . substr($input,$i + 1);
            tryCombination($remaining,$next,$storage);
        }
    }


}

$final = bruteforce('yourData');
echo count($final);
print_r($final);
于 2011-02-03T15:45:21.353 に答える