How to combine 3-4 characters from the six characters in a-f?

Source: Internet
Author: User
{Code ...} take 3 or 4 characters from the array $ arr and combine them into new characters, such as abc, abd, abe, and abcd, when the order is different, abc and acb are considered different. New characters are stored in the array, $ newArr [] & #039; abc & #039 ;; $ newArr [] & #039; abd & #039; $ n...
$arr=['a','b','c','d','e','f'];

Take 3 or 4 characters from the array $ arr and combine them into new characters, such as abc, abd, abe, and abcd, when the order is different, abc and acb are considered different, and new characters are stored in the array,
$ NewArr [] = 'abc ';
$ NewArr [] = 'abd ';
$ NewArr [] = 'AB ';
$ NewArr [] = 'abcd ';
$ NewArr [] = 'acbd ';
...

How to list all the situations?

Reply content:
$arr=['a','b','c','d','e','f'];

Take 3 or 4 characters from the array $ arr and combine them into new characters, such as abc, abd, abe, and abcd, when the order is different, abc and acb are considered different, and new characters are stored in the array,
$ NewArr [] = 'abc ';
$ NewArr [] = 'abd ';
$ NewArr [] = 'AB ';
$ NewArr [] = 'abcd ';
$ NewArr [] = 'acbd ';
...

How to list all the situations?

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);}

Recursion can be used to achieve

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.