An algorithm that combines all array elements

Source: Internet
Author: User
Ask experts for an algorithm that combines all array elements.

Array:
$ Arr = array (A, B, C );
Required output:
A
AB
AC
ABC
B
BA
BC
C
CA
CB

It is to output all the combinations of array elements. The order is not required. you only need to be able to input all the elements.


Reply to discussion (solution)

An ACB, BAC, BCA, CAB, and CBA will also be output.

That is
Array ([0] => A [1] => AB [2] => AC [3] => ABC [4] => ACB [5] => B [6] => BA [7] => BC [8] => BAC [9] => BCA [10] => C [11] => CA [12] => CB [13] => CBA [14] => CAB)

What happened to Deere? Please refer to the essence area

$ Ar = array ('A', 'B', 'C'); $ res = array_chunk ($ ar, 1); for ($ I = 1; $ I
 
  
Array
  
(
[0] =>
[1] => B
[2] => C
[3] => AB
[4] => AC
[5] => BA
[6] => BC
[7] => CA
[8] => CB
[9] => ABC
[10] => ACB
[11] => BAC
[12] => BCA
[13] => CAB
[14] => CBA
)

   0) {for ($ I = 0; $ I
   

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.