Php array combination $ set & nbsp; array (a, B, c, d); how to combine arrays, the output result is abcbabacadbcbd ------ solution ------------------ $ set & nbsp; array (a, B, c, d); $ res & nbsp; $ set; for ($ i0, 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
------ Solution --------------------
$set = array('a','b','c','d');
$res = $set;
for($i=0, $p=1; $i
$res[] = $res[$i] . $set[$p];
}
print_r($res);
Array
(
[0] =>
[1] => B
[2] => c
[3] => d
[4] => AB
[5] => bc
[6] => cd
)
------ Solution --------------------
Reference:
$set = array('a','b','c','d');
$res = $set;
for($i=0, $p=1; $i
$res[] = $res[$i] . $set[$p];
}
print_r($res);
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.
$set = array('a','b','c','d');
$len = count($set);
$res = array();
for($i=0,$k=$len;$i<$len;$i++){
$res[$i] = $set[$i];
for($j=$i+1;$j<$len;$j++){
$res[$k++] = $set[$i].$set[$j];
}
}
ksort($res);
var_dump($res);
?>
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)
------ Solution --------------------
$set = array('a','b','c','d');
$arr=array();
for($j=0;$j
$arr[]=$set[$j];
}
foreach($set as $k=>$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
)