开发者

compare two arrays of numbers and remove duplicates in php

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.

开发者_如何学GoAny help or suggestions is appreciated thanks :)


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)


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜