1

在两个关联数组之间获取匹配键的最佳方法是什么:

Array (
    [array_1] => Array (
        [abc] => 111
        [def] => 222
    ),
    [array_2] => Array (
        [ghi] => 995
        [jkl] => 996
        [mno] => 997
    )
)

Array (
    [array_1] => Array (
        [123] => 111
        [345] => 222
    ),
    [array_2] => Array (
        [123] => 995
        [432] => 996
        [345] => 997
    ),
    [array_3] => Array (
        [456] => 995
        [345] => 996
        [234] => 997
    )
)

我希望返回一个仅包含值的数组:array_1array_2.

array_intersect在这里不起作用,array_intersect_key 也不会,因为它会返回子数组

我想要这个结果:

array('array_1','array_2')

因为这些是匹配的键

4

1 回答 1

2
$theListOfKeysWotIWant = array_keys(
    array_intersect_key(
        $array1,
        $array2
    )
);
于 2013-01-30T15:11:09.087 回答