我有两个数组。
$queue_ids
和 $subscriber_results
。
$queue_ids
输出:
Array ( [0] => 3 [1] => 4 [2] => 5 )
$subscriber_results
输出:
Array ( [0] => Array ( [id] => 3 [email] => <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7d3c2d4d396e7d3c2d4d389c4c8ca" rel="noreferrer noopener nofollow">[email protected]</a> [subscribed] => 1436264818 ) [1] => Array ( [id] => 4 [email] => <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7b3a2b4b3f587b3a2b4b3e9a4a8aa" rel="noreferrer noopener nofollow">[email protected]</a> [subscribed] => 1436265909 ) [2] => Array ( [id] => 5 [email] => <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80f4e5f3f4b3c0f4e5f3f4aee3efed" rel="noreferrer noopener nofollow">[email protected]</a> [subscribed] => 1436265919 ) )
我需要匹配这两个数组,以从 $subscriber_results
数组中获取 $queue_ids
数组中这些键的 email
记录.
我尝试使用 array_keys() 但无法让它工作。
有人能告诉我如何做到这一点吗?
最佳答案
您可以使用array_column提取一个数组,其中 id 是数组索引(键),电子邮件是值。然后compare it到队列 ID 列表 flipped所以这些值就是索引(键)。
$matchingEmails = array_intersect_key(array_column($subscriber_results, "email", "id"), array_flip($queue_ids));
关于php - 匹配两个数组以从第二个数组中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31269643/