# ket tomb kulcs alapu metszetet szamitja ki, az erteken is ellenorzest vegez
#
# 计算数组的(基于键的)交集(检查值)
# 使用:$result_array = array_intersect_assoc($a1, $a2, $a3,..);
#
##
# 原始代码来自 [jochem at iamjochem dawt com] : array_diff_keys()
<?php
function array_intersect_assoc() {
$args = func_get_args();
$res = $args[0];
for ($i=1;$i<count($args);$i++) {
if (!is_array($args[$i])) {continue;}
foreach ($res as $key => $data) {
if ( (!array_key_exists($key, $args[$i])) || ( (isset($args[$i][$key])) && ($args[$i][$key] !== $res[$key]) ) ) {
unset($res[$key]);
}
}
}
return $res;
}
?>
<?php
$array1 = array("a"=>"green", "b"=>"brown", "c"=>"blue", "red");
$array2 = array("a"=>"green", "b"=>"yellow", "c"=>"yellow", "red");
$a = array('a'=>'green', 'b'=>'brown', 'c'=>'yellow');
$b = array('a'=>'green', 'b'=>'brown', 'c'=>'yellow', 'e'=>'yellow');
$result_array = array_intersect_assoc($a, $b, $array1, $array2);
?>
$args 数组将如下所示
(
0 =>
(
a => green
b => brown
c => yellow
)
1 =>
(
a => green
b => brown
c => yellow
e => yellow
)
2 =>
(
a => green
b => brown
c => blue
0 => red
)
3 =>
(
a => green
b => yellow
c => yellow
0 => red
)
)
$result_array 将如下所示
(
a => green
)