我有两个数组我希望匹配第二个数组['Name']
值的[Seltemgr]
值,如果['Name']=>value == [Seltemgr]=>value
然后<input type="checkbox" checked="checked">
其他未选中,这是否可以匹配两个多维数组具有不同元素和不同键的不同。
Array
(
[0] => Array
(
[tnid] => 45
[Name] => Financial Tips
[Email] => Array
[Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/5
)
[1] => Array
(
[tnid] => 42
[Name] => Products
[Email] => Array
[Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/2
)
[2] => Array
(
[tnid] => 44
[Name] => Health Tips
[Email] => Array
[Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/4
)
[3] => Array
(
[tnid] => 43
[Name] => Personal Events
[Email] => Array
[Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/3
)
[4] => Array
(
[tnid] => 41
[Name] => Calendar
[Email] => Array
[Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/1
)
)
Array
(
[0] => Array
(
[emarketid] => 77
[agentid] => 81
[customerid] => 16901
[Seltemgr] => Calendar
[seltemname] =>
)
[1] => Array
(
[emarketid] => 78
[agentid] => 81
[customerid] => 16901
[Seltemgr] => Financial Tips
[seltemname] =>
)
[2] => Array
(
[emarketid] => 79
[agentid] => 81
[customerid] => 16901
[Seltemgr] => Merry Christmas
[seltemname] =>
)
[3] => Array
(
[emarketid] => 80
[agentid] => 81
[customerid] => 16901
[Seltemgr] => Drip financial tip 3
[seltemname] =>
)
)
答案 0 :(得分:0)
$match = [];
foreach ($array1 as $k1=>$a1){
foreach($array2 as $k2=>$a2){
if($a2['Seltemgr'] == $a1['Name']){
$match[] = array($k1,$k2);
}
}
}
所以$ match包含Name和Seltemgr匹配的每个数组的索引。不是说这是执行此操作的最佳方式,但交叉函数通常需要键才能匹配。