How to implement the Program to store all the possibilities in an array. We can repeat aaaa. It is best to implement PHP to store all the possibilities in an array and how to implement the program.
It can be repeated, such as aaaa. It is best to implement it in PHP.
Reply content:
How to implement the Program to store all the possibilities in an array.
It can be repeated, such as aaaa. It is best to implement it in PHP.
Python
import itertoolsprint list(itertools.permutations(["a","b","c","d","e","f","g"],4))
Php
You can try this:
Http://www.honglei.net /? P = 167
Do you want to consider the existence of aaaa? In fact, we can consider encoding them. Suppose abcdefg corresponds to 0123456 respectively, then all the situations are:
0000 (that is, 0 )~ 6666 all numbersLa.
Ps: in hexadecimal notation
Code directly, four for loops, simple, violent, and fast
function dfs($pre, $chars, $arr, $lenArr) { if(!empty($pre) && in_array(strlen($pre), $lenArr)){ $arr[] = $pre; } if(!empty($chars)) { foreach ($chars as $char) { $tempChars = array(); foreach ($chars as $c) { if ($c !== $char) { $tempChars[] = $c; } } $arr = $this->dfs($pre.$char, $tempChars, $arr, $lenArr); } } return $arr;}function get_combine() { $chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g'); $combineArray = array(); $combineArray = $this->dfs('', $chars, $combineArray, array(4)); echo count($combineArray).'
'; var_dump($combineArray);}