如何在smarty中合并具有相同值的数组?

how to merge array with the same value in smarty?

我有两个数组,我想在每个数组中使用相同的值进行两个合并..

第一个数组是:

    [0] => Array
        (
            [id] => 1
            [uid] => 0090000157
            [cid] => 0090000007
            [extension] => 202
            [secret] => Myojyo42f!
            [leader] => 1
            [simultaneous] => 
            [confbridge_id] => 2
            [created_at] => 2015-07-26 12:20:20
            [updated_at] => 2015-07-26 12:20:20
        )

    [1] => Array
        (
            [id] => 2
            [uid] => 0090000159
            [cid] => 0090000007
            [extension] => 
            [secret] => Myojyo42f!
            [leader] => 
            [simultaneous] => 
            [confbridge_id] => 2
            [created_at] => 2015-07-26 14:23:41
            [updated_at] => 2015-07-26 14:23:41
        )

)

第二个数组是:

Array
(
    [0] => Array
        (
            [_id] => 55b52f4c2bab38fc63b6272a
            [event] => ConfbridgeJoin
            [channel] => SIP/peer_voip301confbridge-0000001b
            [uniqueid] => 1437937478.63
            [conference] => 0090000156
            [calleridnum] => 0090000157
            [calleridname] => 0090000157
            [__v] => 0
            [sipSetting] => Array
                (
                    [accountcode] => 
                    [accountcode_naisen] => 202
                    [extentype] => 0
                    [extenrealname] => 
                    [name] => 0090000157
                    [secret] => Myojyo42f!
                    [username] => 0090000157
                    [context] => innercall_xdigit
                    [gid] => 101
                    [cid] => 0090000007
                )

        )

    [1] => Array
        (
            [_id] => 55b53a2e2bab38fc63b6272b
            [event] => ConfbridgeJoin
            [channel] => SIP/peer_voip301confbridge-0000001c
            [uniqueid] => 1437940260.66
            [conference] => 0090000156
            [calleridnum] => 0090000158
            [calleridname] => UID2
            [__v] => 0
            [sipSetting] => Array
                (
                    [accountcode] => 
                    [accountcode_naisen] => 203
                    [extentype] => 0
                    [extenrealname] => 
                    [name] => 0090000158
                    [secret] => Myojyo42f!
                    [username] => 0090000158
                    [context] => innercall_xdigit
                    [gid] => 101
                    [cid] => 0090000007
                )

        )

)

我想合并具有相同值的数组,例如:

第一个数组 = [uid] => 0090000157 第二个数组有 = [calleridnum] => 0090000157

可以合并吗?

这是我的代码

{foreach from=$participants item=participant key=p }
  {foreach from=$conference_participants item=conference_participant key=c}
            {if$participants.calleridnum == $conference_participants.uid}
              //how to get data here   ?    

            {/if}
  {/foreach}
{/foreach}

这就是您要找的东西吗?

抱歉所有更改,我应该测试一下...grr

(我把它放在 PHPFiddle 中:

<pre>
<?php
$participants = [
    [   'calleridnum' => 1,
        'test' => 'yay' 
    ]
];
$conferance_participants = [
    [   'uid' => 1,
        'test' => 'yay2',
        'dit' => 'deze'
    ]
];

foreach ($participants as $participant=>$p) {
    foreach ($conferance_participants as $conferance_participant=>$c) {

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

            // ID's match do the magic here
            foreach ( $c as $key=>$val ) {
                if (!isset($p[$key])) {
                    // Value is new, copy the conferance_participant to the participant
                    $participants[$participant][$key] = $val;
                }
            } // Merging data

        } // If: Match

    } 
}

print_r( $participants );
?>

)