php 数组去除重复值
程序员文章站
2022-06-03 10:30:50
...
我要把花红线的键值去过 只留下后面的两个键值 应该怎么实现
Array
(
[6] => 42
[7] => 43
)
回复讨论(解决方案)
$arr=array(38,39,41,38,39,41,42,43);$c=array_count_values($arr);function foo($v){ global $c; if($c[$v]==1){ return true; } return false;}print_r(array_filter($arr,'foo'));
Array
(
[6] => 42
[7] => 43
)
$ar = array(38, 39, 40, 41, 38, 39, 40, 41, 42, 43);foreach(array_count_values($ar) as $k=>$v) if($v == 1) $res[] = $k;print_r($res);Array ( [0] => 42 [1] => 43 )
也可以这样写
$ar = array(38, 39, 40, 41, 38, 39, 40, 41, 42, 43);$t = array_intersect(array_count_values($ar), array(1));$t = array_intersect($ar, array_keys($t));print_r($t);Array ( [8] => 42 [9] => 43 )
上一篇: OPENBIZ - 使应用开发不同于编程_PHP教程
下一篇: springmvc文件上传