I have a set of ids and names in an associative array and in my other array I have my list of id's that I want to compare against the first list.
我在一个关联数组中有一组id和名称,在我的另一个数组中,我有我想要与第一个列表进行比较的id列表。
I'd like to be able to perform an intersection type search function without losing the names from the associative array.
我希望能够执行交集类型搜索功能,而不会丢失关联数组中的名称。
I've though about doing a nested foreach, but it seems like this process could take forever as both arrays could potentially have 70k+ values.
我虽然做了一个嵌套的foreach,但似乎这个过程可能需要永远,因为两个数组都可能有70k +值。
1 个解决方案
#1
$assoc = array(
'a' => 'one',
'b' => 'two',
);
$array = array('b', 'c', 'd');
$match = array_intersect_key($assoc, array_flip($array));
print_r($match);
outputs:
Array
(
[b] => two
)
which I believe is what you're after.
我相信你所追求的是什么。
#1
$assoc = array(
'a' => 'one',
'b' => 'two',
);
$array = array('b', 'c', 'd');
$match = array_intersect_key($assoc, array_flip($array));
print_r($match);
outputs:
Array
(
[b] => two
)
which I believe is what you're after.
我相信你所追求的是什么。