array_intersect_key() 這個函式,可以比對出 N 個陣列中相同的index

範例

$arr1 = array(
    "a-key" => 1,
    "b-key" => 2,
    "c-key" => 3
);

$arr2 = array(
    "a-key" => 3,
    "b-key" => 4,
    "d-key" => 4,
);

print_r(array_intersect_key($arr1, $arr2));
Categories: PHP