Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove duplicates from array

Tags:

php

I have two arrays, like this:

$array1 = array(
'ADAIR',
'ADAM',
'ADAMINA',
'ADDISON',
'ADDY',
'ADELLE',
'ADEN',
'ADOLPH',
'ADRIANNA'
);

$array2 = array(
'ADAIR',
'ADAMINA',
'ADRIANNA'
);

How do I make a third array, without duplicates? We should take first array and remove from it duplicates from second array.

like image 677
Jasper Avatar asked Apr 22 '26 19:04

Jasper


1 Answers

Use Array-diff

$array3=array_diff($array1,$array2);

Returns an array containing all the entries from array1 that are not present in any of the other arrays.

like image 94
RiaD Avatar answered Apr 25 '26 07:04

RiaD



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!