开发者

how do i create all possible letter combinations with php [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I l开发者_开发知识库ooked around stack overflow and couldn't find a sample on what I needed. how would I create something like this?

so lets say i want all possible combinations of up to 5 characters. the output would look like this:

aaaaa
aaaab
aaaac
aaaad

..etc


Ok, because I believe that you don't have any clue what to do, I will give you a short code example. It is not perfect and its written down in a couple of minutes but it should bring you on the right way:

$values = 'abcd';
run(strlen($values), 0 );

function run($length, $pos, $out = '' ) {
    global $values;

    for ($i = 0; $i < $length; ++$i) {
        if ($pos < $length ) {
            run($length, $pos + 1, $out . $values[$i]);
        }
    }
    echo $out.PHP_EOL;
}

Next time try first and post your question with the code you have written even if it is nearly nothing and looks stupid for you. But in the end it will show that you make own work and don't hope to get your work done for free without thinking by yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜