如何从第二个数组中删除对象$ conferance_participants
如果此陈述为真
如果$participants['calleridnum'] == $conferance_participants['uid']
<?php
$participants = [
[ 'calleridnum' => 1,
'test' => 'yay'
]
];
$conferance_participants = [
[ 'uid' => 1,
'test' => 'yay2',
'dit' => 'deze'
],
[ 'uid' => 2,
'test' => 'test',
'dit' => 'wew'
]
];
$uniques = array_unique(array_merge($participants, $conferance_participants));
print_r( $uniques );
?>
如果此陈述为真
如果$participants['calleridnum'] == $conferance_participants['uid']
我想从第二个具有相同值
的数组中删除该对象我希望输出像
Array
(
[0] => Array
(
[calleridnum] => 1
[test] => yay
)
[2] => Array
(
[uid] => 2
[test] => test
[dit] => wew
)
)
答案 0 :(得分:1)
foreach ($participants as $key=>$p) {
foreach ($conferance_participants as $key=>$cp) {
if ($p['calleridnum'] == $cp['uid']) {
unset($participants[$key]);
}
}
}
$result = array_merge($conferance_participants, $participants);
或者,如果您不想更改$ conferance_participants数组,请执行
$result = array();
foreach ($conferance_participants as $key => $cp) {
if ($cp['uid'] != $participants['calleridnum'])
$result[] = $cp;
}
$result[] = $participants;