How to compare two arrays and remove duplicates
by Jayanthi[ Edit ] 2014-12-03 19:50:59
How to compare two arrays and remove duplicates
Syntax
array_diff(firstarray, secondarray,[thirdarray....]);
the firstarray returns campares value.
Code
$tldvals=array('netuk','tv','name','org','genin','ukcom','nzcom','secom','netin','orgin','firmin','tv.co');
$needle = array('in','uk','nz','com','co','net','org','tv','name');
$arr_1 = array_diff($tldvals, $needle);
$arr_2 = array_diff($needle, $tldvals);
print_r($arr_1);
print_r($arr_2);
First Array Output is:
Array ( [0] => netuk [4] => genin [5] => ukcom [6] => nzcom [7] => secom [8] => netin [9] => orgin [10] => firmin [11] => tv.co )
Second Array Output Is:
Array ( [0] => in [1] => uk [2] => nz [3] => com [4] => co [5] => net )