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
精彩评论