Sam Sam - 1 year ago 58
PHP Question

How can we find the Duplicate values in array using php?

I would like to know, how can we detect the duplicate entries in array...

Something like

$array = array("", "","","","","","","","","") ;

I want to get the number of Duplicity used in array (C class unique).
like this = unique = Duplicate = unique = unique = Duplicate = Duplicate = unique = Duplicate = unique = Duplicate (Modified)

I tried this code like this style

$array2 = array() ;

foreach($array as $list ){

$ips = $list;

$ip = explode(".",$ips);

$rawip = $ip[0].".".$ip[1].".".$ip[2] ;



but i am unable to set the data in right manner and also unable to make the loop for matching the data.

modified values



Answer Source

Try this : this will give you the count of each value

$array = array("", "","","","","","","","") ;

$cnt_array = array_count_values($array)

echo "<pre>"; 

$res = array();
foreach($cnt_array as $key=>$val){
   if($val == 1){
      $res[$key] = 'unique';
      $res[$key] = 'duplicate';

echo "<pre>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download