RE: [PHP] Array differences
| From: | Ashley M. Kirchner | Date: | Wed, 14 Apr 2010 16:20:33 +0000 |
| Subject: | RE: [PHP] Array differences | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304093@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: lala [mailto:lala@mail.theorb.net]
> Sent: Wednesday, April 14, 2010 10:15 AM
> To: Ashley M. Kirchner
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Array differences
>
> Ashley M. Kirchner wrote:
> >
> > $array1 = array(1, 2, 3, 4, 5, 6);
> > $array2 = array(1, 3, 2, 8, 9);
> > $diff1 = array_diff($array1, $array2);
> > $diff2 = array_diff($array2, $array1);
> > $result = array_unique(array_merge($diff1, $diff2));
> >
> > => (4, 5, 6, 8, 9)
>
> Hi Ash,
>
> Isn't the array_unique() unnecessary?
>
> Mike
Thinking about it, it should be unnecessary, but at the same time I want to absolutely sure that I
get unique values out of the two diffs.
Ash