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


i know, how can detect duplicate entries in array...

something

$array = array("192.168.1.1", "192.168.2.1","192.168.3.1","192.168.4.1","192.168.2.1","192.168.2.1","192.168.10.1","192.168.2.1","192.168.11.1","192.168.1.4") ; 

i want number of duplicity used in array (c class unique).

192.168.1.1 = unique 192.168.2.1 = duplicate 192.168.3.1 = unique 192.168.4.1 = unique 192.168.2.1 = duplicate 192.168.2.1 = duplicate 192.168.10.1 = unique 192.168.2.1 = duplicate 192.168.11.1 = unique 192.168.1.4 = duplicate (modified) 

i tried code style

$array2 = array() ;  foreach($array $list ){  $ips = $list;  $ip = explode(".",$ips);  $rawip = $ip[0].".".$ip[1].".".$ip[2] ;  array_push($array2,$rawip);  } 

but unable set data in right manner , unable make loop matching data.

modified values

thanks

sam

try : give count of each value

$array = array("192.168.1.1", "192.168.2.1","192.168.3.1","192.168.4.1","192.168.2.1","192.168.2.1","192.168.10.1","192.168.2.1","192.168.11.1") ;  $cnt_array = array_count_values($array)  echo "<pre>";  print_r($cnt_array);  $res = array(); foreach($cnt_array $key=>$val){    if($val == 1){       $res[$key] = 'unique';    }    else{       $res[$key] = 'duplicate';    } }  echo "<pre>"; print_r($res); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -