How do I take a combination of 3-4 characters from a-f six characters?

Source: Internet
Author: User
$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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.