开发者

How to do the Array Sorting for only Double Values

开发者 https://www.devze.com 2023-03-13 00:42 出处:网络
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)

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

精彩评论

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