How to merge subarray values and remove duplicates?

user198729 picture user198729 · Jan 26, 2010 · Viewed 13.8k times · Source
$arr[] = array('A','B');
$arr[] = array('C','B');
...

I need to get the merged result of all sub array of $arr .

And for duplicated entries,should fetch only one.

Answer

bish picture bish · Jan 26, 2010

If you really don't want to loop, try this:

$arr[] = array('A','B');
$arr[] = array('C','B');
$arr[] = array('C','D');
$arr[] = array('F','A');
$merged = array_unique(call_user_func_array('array_merge', $arr));