How to do the Array Sorting for only Double Values
I would like to know more about the array sorting. Like we have a example of source:
array(78,124,54,84,124,658,54,84)
here we just want to create another array, with only unique the double values,see in above array 124,54,84 is repeated two times, We only consider these values(we can make any changes for Single Values). And We just want refreshed a开发者_Go百科rray like this one:
array(124,54,84)
$values=array_count_values($array);
foreach($values as $key => $val)
{
if ($val >=2)
{
$newarray[]=$key;
}
}
print_r($newarray);
I guess you are looking for this:
$a = array(78, 124, 54, 84, 124, 658, 54, 84);
$counts = array_count_values($a);
$result = array();
foreach ($counts as $key => $value)
{
if ($value == 2)
$result[] = $key;
}
print_r($result);
Output:
Array
(
[0] => 124
[1] => 54
[2] => 84
)
精彩评论