Question

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 :)

Was it helpful?

Solution

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)

OTHER TIPS

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

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

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.

Use the array_unique function. Here is an example:

$start = array(1,2,3,3,4,4,4,5);
$unique_result = array_unique($start);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top