Home > Backend Development > PHP Tutorial > 删数组有得有反复值

删数组有得有反复值

WBOY
Release: 2016-06-13 12:59:56
Original
914 people have browsed it

删数组有得有重复值
有原数组a  里有值 $a=array(a,b,c);
比较数组b  里有值 $b=array(b);

两个相比较,得到$c= array(a,c);

请问一下,这个怎么做。
------解决方案--------------------
循环判断或者移除呗
------解决方案--------------------
用array_diff ($array_a,$array_b)
------解决方案--------------------
array_diff ,数组相减
------解决方案--------------------

$a = array(a,b,c);<br />
$b = array(b);<br />
print_r(array_diff($a, $b));
Copy after login
Array
(
    [0] => a
    [2] => c
)

------解决方案--------------------

引用:
用array_diff ($array_a,$array_b)
 `
------解决方案--------------------
http://baike.baidu.com/view/4067743.htm
------解决方案--------------------
其实你的意思就是要找出2个数组的中差集,array_diff()这个系统函数即可
------解决方案--------------------
array_diff()手册里有

------解决方案--------------------
引用:
用array_diff ($array_a,$array_b)


$c = array_diff($a,$b);
echo "c = {";
foreach($c as $key => $value)
{
echo $value.",";
}
echo "}
\n";
------解决方案--------------------
引用:
用array_diff ($array_a,$array_b)

多看看手册的函数
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