php 数组除开重复值

WBOY
Release: 2016-06-13 12:52:21
Original
773 people have browsed it

php 数组去除重复值



我要把花红线的键值去过  只留下后面的两个键值   应该怎么实现

数组
------解决方案--------------------
$arr=array(38,39,41,38,39,41,42,43);<br />
$c=array_count_values($arr);<br />
function foo($v){<br />
    global $c;<br />
    if($c[$v]==1){<br />
		  return true;<br />
	}<br />
	return false;<br />
}<br />
print_r(array_filter($arr,'foo'));
Copy after login

Array
(
[6] => 42
[7] => 43
)
------解决方案--------------------
$ar = array(38, 39, 40, 41, 38, 39, 40, 41, 42, 43);<br />
foreach(array_count_values($ar) as $k=>$v)<br />
  if($v == 1) $res[] = $k;<br />
<br />
print_r($res);
Copy after login
Array ( [0] => 42 [1] => 43 ) 
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template