Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge arrays without same values

Tags:

arrays

merge

php

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?

like image 833
Lewis Avatar asked Nov 21 '25 12:11

Lewis


1 Answers

$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!

like image 170
Graham Ritchie Avatar answered Nov 24 '25 02:11

Graham Ritchie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!