开发者

merging two arrays and keep duplicate values

Is there a php function to merge 2 arrays and keep duplicates?

Like:

$a=array('a','b','c');
$b=array('b','c',开发者_StackOverflow中文版'b');
array_merge2($a,$b);
//result: array('a','b','c','b','c','b');

thanks

add1:

what the... i previously tested array_merge and it didn't keep duplicate values =/


In the examples for array_splice it shows how to add the contents of one array onto the end of another. Just replace the last parameter with your array.

array_splice($input, count($input), 0, array($x, $y));

So in your example:

$a=array('a','b','c');
$b=array('b','c','b');
array_splice($a, count($a), 0, $b);


array_merge keeps the duplicates.

http://codepad.org/XGcMAi3z

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜