欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 数组组合

程序员文章站 2022-06-06 23:41:21
...
$set = array('a','b','c','d');

该如何把数组组合,输出的结果是
a
b
c
b
ab
ac
ad
bc
bd


回复讨论(解决方案)

$set = array('a','b','c','d');$res = $set;for($i=0, $p=1; $iArray  
(
[0] => a
[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; $iArray   
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => ab
[5] => bc
[6] => cd
)
版主这个输出的和楼主的不一样啊,我没太搞懂楼主到底是要怎么组合输出这个数组,我的解决方法如下,这里不用输出cd就可以了


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  
Array(    [0] => a    [1] => b    [2] => c    [3] => d    [4] => ab    [5] => ac    [6] => ad    [7] => bc    [8] => bd    [9] => cd)
相关标签: 数组 php 组合