交集array_intersect
$a1=array("a"="d","b"="gen","c"="blue","d"="yellow");$a2=array("e"="d","f"="gen","g"="blue");$sult=array_intersect($a1,$a2);print_r($sult);
结果
Array([a]=d[b]=gen[c]=blue)
并集
$a1=array("d","gen");$a2=array("blue","yellow");$sult=array_merge($a1,$a2);print_r($sult);
结果
Array([0]=d[1]=gen[2]=blue[3]=yellow)
注意下:如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。
差集array_diff
$a1=array("a"="d","b"="gen","c"="blue","d"="yellow");$a2=array("e"="d","f"="gen","g"="blue");$sult=array_diff($a1,$a2);print_r($sult);
结果
Array([d]=yellow)
记得