1

OK i have two groups of mobile numbers (from mysql) which i need to process, the problem is i need to remove duplicate numbers from the results.

Someone told me about "array_intersect" but I am not very good at these things and I don't see any good examples on the PHP website.

Any help or suggestions is appreciated thanks :)

Kyle Hudson
  • 878
  • 1
  • 14
  • 26
  • possible duplicate of [PHP combining arrays.](http://stackoverflow.com/questions/3941302/php-combining-arrays) – Gordon Oct 15 '10 at 20:53

5 Answers5

5

array_intersect isn't quite right — that finds numbers that are in both arrays

$uniques = array_unique(array_merge($array1, $array2));

This merges the two arrays together and then filters out all the unique results (with array_unique)

VoteyDisciple
  • 36,263
  • 5
  • 90
  • 93
3

Use the array_unique function.

$myArray = array(1, 1, 2, 3, 3, 5);
$myArray2 = array_unique($myArray);

http://php.net/manual/en/function.array-unique.php

Mike
  • 2,802
  • 10
  • 41
  • 54
2

Put both lists into one array and then run it through array_unique() .

Alex Howansky
  • 47,154
  • 8
  • 74
  • 95
2

As you wrote about using MySQL, better try using something like

SELECT DISTINCT phone_number FROM table

With DISTINCT each row in the resultset will be unique.

matthiasz
  • 21
  • 1
1

Use the array_unique function. Here is an example:

$start = array(1,2,3,3,4,4,4,5);
$unique_result = array_unique($start);
Michael Goldshteyn
  • 68,941
  • 23
  • 129
  • 179