Lewis
Lewis

Reputation: 14906

merge arrays without same values

I have two arrays:

$a = array('a','b','c');
$b = array('b','c','d','e');

What must I do in order to get array ('a','d','e') via array $a and $b?

Upvotes: 3

Views: 46

Answers (1)

GrahamTheDev
GrahamTheDev

Reputation: 24865

$a = array('a','b','c');
$b = array('b','c','d','e');
$output = array_merge(array_diff($a, $b), array_diff($b, $a));

I think that is right - is off top of my head.

Yup http://ideone.com/56V0d0 <- fiddle here - seems to work!

Upvotes: 5

Related Questions