我有这两个associative arrays
//针阵列
$a = array(
"who" => "you",
"what" => "thing",
"where" => "place",
"when" => "hour"
);
// haystack数组
$b = array(
"when" => "time",
"where" => "place",
"who" => "you",
"what" => "thing"
);
我想检查$a
是否与b
匹配,并且确切key
和value
如果$a
中的每个键和值都与$b
中的完全匹配....我想将变量$c
的值递增1,依此类推。
$c
的值增加3
$c = "3";
我希望有些天才可以帮助我...
答案 0 :(得分:13)
你可以查看php的array_diff_assoc()
函数或array_intersect()
函数。
以下是计算匹配值的示例:
<?php
$a = array(
"who" => "you",
"what" => "thing",
"where" => "place",
"when" => "hour"
);
// the haystack array
$b = array(
"when" => "time",
"where" => "place",
"who" => "you",
"what" => "thing"
);
$c = count(array_intersect($a, $b));
echo $c;
?>
CODEPAD链接。