比较PHP中的两个数组 [英] Compare two arrays in php
本文介绍了比较PHP中的两个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个名为 行和联系人 的数组。
I have two arrays named rows and contacts.
第一个数组 行 就像:
The first array rows is like :
Array
(
[0] => email@gmail.com
[1] => test@gmail.com
[2] => tester@gmail.com
[3] => vin@gmail.com
)
第二个数组 联系人 如下:
The second array contacts is as :
Array
(
[test@gmail.com] => test@gmail.com
[ram@gmail.com] => Ram
[vin@gmail.com] => Vinay
[man_test@yahoo.com] => Manoj
[homan@rediffmail.com] => Homan
)
我想要的是 联系人 数组,如下所示:
What I want is the contacts array to be as :
Array
(
[ram@gmail.com] => Ram
[man_test@yahoo.com] => Manoj
[homan@rediffmail.com] => Homan
)
编辑
我尝试了一些功能,例如 array _diff(),array_keys()等,但是它们没有给我想要的输出,可能是我无法正确使用它们.... !!
Edit
I tried some functions like array_diff(), array_keys() etc. but they are not giving me the desired output, may be I am not able to use them correctly....!
我不想为此使用循环,因为给定的数组仅是示例数据,但实际上它们非常大。
I don't want to use loop for this purpose because the given arrays are only sample data but in real they are very huge.
请帮助... ..
在此先感谢.....
Thanks in Advance.....
推荐答案
另一种方式:
$contacts = array_diff_key($contacts, array_flip($rows));
这篇关于比较PHP中的两个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文