$arr=['a','b','c','d','e','f'];
Remove 3 or 4 characters from the array $arr (two cases are considered) combined into new characters, such as ABC,ABD,ABE,ABCD, while considering the different order, ABC and ACB are considered different cases, the new characters are stored in the array,
$NEWARR []= ' abc ';
$NEWARR []= ' Abd ';
$NEWARR []= ' Abe ';
$NEWARR []= ' ABCD ';
$NEWARR []= ' ACBD ';
...
How do I enumerate all the circumstances?
Reply content:
$arr=['a','b','c','d','e','f'];
Remove 3 or 4 characters from the array $arr (two cases are considered) combined into new characters, such as ABC,ABD,ABE,ABCD, while considering the different order, ABC and ACB are considered different cases, the new characters are stored in the array,
$NEWARR []= ' abc ';
$NEWARR []= ' Abd ';
$NEWARR []= ' Abe ';
$NEWARR []= ' ABCD ';
$NEWARR []= ' ACBD ';
...
How do I enumerate all the circumstances?
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'); $combineArray = array(); $combineArray = $this->dfs('', $chars, $combineArray, array(3, 4)); echo count($combineArray).'
'; var_dump($combineArray);}
Recursive can be used to achieve