Php array combination

Source: Internet
Author: User
Php array combination $ set = array ('A', 'B', 'C', 'D ');

How to combine arrays? the output result is
A
B
C
B
AB
Ac
Ad
Bc
Bd


Reply to discussion (solution)

$ Set = array ('A', 'B', 'C', 'D'); $ res = $ set; for ($ I = 0, $ p = 1; $ I
 
  
Array
  
(
[0] =>
[1] => B
[2] => c
[3] => d
[4] => AB
[5] => bc
[6] => cd
)

$ Set = array ('A', 'B', 'C', 'D'); $ res = $ set; for ($ I = 0, $ p = 1; $ I
   
    
Array
    
(
[0] =>
[1] => B
[2] => c
[3] => d
[4] => AB
[5] => bc
[6] => cd
)


The outputs of the moderator are different from those of the landlord. I am not sure how the moderator combines the outputs of this array. my solution is as follows: no cd output is needed here.
     


array (size=10)  0 => string 'a' (length=1)  1 => string 'b' (length=1)  2 => string 'c' (length=1)  3 => string 'd' (length=1)  4 => string 'ab' (length=2)  5 => string 'ac' (length=2)  6 => string 'ad' (length=2)  7 => string 'bc' (length=2)  8 => string 'bd' (length=2)  9 => string 'cd' (length=2)

$set = array('a','b','c','d');$arr=array();for($j=0;$j
     
      $v){    for($i=$k;$i<=(3-$v);$i++){        if($v==$set[$i]) continue;        $arr[]=$v.$set[$i];    }}print_r($arr);
     

Array(    [0] => a    [1] => b    [2] => c    [3] => d    [4] => ab    [5] => ac    [6] => ad    [7] => bc    [8] => bd    [9] => cd)

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.