如果发现数组中的重复值,则删除数组中的值



我有一个这样的数组

$callerid = Array ( [1] => <409> [2] => <3214> [3] => <409> [4] => <5674> ) 

我想有这样的输出

Array ( [1] => <3214> [2] => <5674> )

也就是说,如果发现数组中重复出现,我想删除值的出现。

如何实现这一点?

不保留键,但返回正确的值(即,出现次数为 1 的值)

$callerid = array(1 => 409, 2 => 3214, 3 => 409, 4 => 5674);
$calleridCounts = array_count_values($callerid);
$result = array_keys(
    array_intersect($calleridCounts,array(1))
);
var_dump($result);
<?php
$string = Array ( 409,3214,409,5674 ) ;
print_r($string);
foreach($string as $vals){
   $match  = array_keys($string, $vals);
   if(count($match) > 1){
      foreach($match as $ky){
        unset($string[$ky]);
      }
   }
}
print_r($string);
?>

最新更新