how do i create all possible letter combinations with php [closed]
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.
精彩评论