有没有办法做到以下几点:
$array1 = array( "two" => "2", "three" => "3")
$array2 = array("two", "three", "four")
我想将array2
' 值与array1
' 键匹配。匹配后,我想输出array1
的值。
谢谢
就像马克贝克评论的那样,你可以array_flip()
一起使用array_intersect_key()
$array1 = array( "two" => "2", "three" => "3");
$array2 = array("two", "three", "four");
$array2 = array_flip($array2);
print_r(array_intersect_key($array1, $array2) );
输出:
Array
(
[two] => 2
[three] => 3
)
$array1 = array( "two" => "2", "three" => "3");
foreach($array1 as $key=>$val){
$array_1[] = $key;
}
$array2 = array("two", "three", "four");
$result = array_diff($array2, $array_1);
print_r($result);