如何比较数组中的三个值并合并


How to compare three values in a array and merge?

如何与相同的值合并数组?

我有三个数组:$participants, $conferance_participants和$contacts

我想比较这三个数组的值并合并

例如:

如果$participants['calleridnum'] == $conferance_participants['uid'] == $contacts['name']

我希望输出是这样的:

Array
(
    [0] => Array
        (
            [calleridnum] => 1
            [test] => yay
            [uid] => 1
            [channel] => deze
            [name] => 1
            [limit] => 1
        )
)

这是我到目前为止的代码:

<?php
$participants = [
    [   'calleridnum' => 1,
        'test' => 'yay' 
    ]
];
$conferance_participants = [
    [   'uid' => 1,
        'test' => 'yay2',
        'channel' => 'deze'
    ]
];
$contacts = [
    [   'name' => 1,
        'test' => 'yay2',
        'limit' => 1
    ]
];
foreach ($participants as $participant=>$p) {
    foreach ($conferance_participants as $conferance_participant=>$c) {
        foreach ($contacts as $contact=>$cs) {

        if (($p['calleridnum'] == $c['uid']) && ($c['uid'] == $cs['name'])) {

                 foreach ( $c as $key=>$val ) {
                     if (!isset($p[$key])) {
                    $participants[$participant][$key] = $val;
                    }
                } 
            } 
        }
    } 
}
print_r( $participants );
?>

尝试调用array_merge(),但您仍然必须考虑使用相同键的不同值(例如:键'test')的值

if (($p['calleridnum'] == $c['uid']) && ($p['uid'] == $c['name'])) {
    $participants[$participant] = array_merge(
        $participants[$participant],
        $conferance_participants[$conferance_participant],
        $contacts[$contact]
    );
}