2

How can i remove object from my 2nd array which is $conferance_participants

if this statement is true

if $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 );
?>

if this statement is true

if $participants['calleridnum'] == $conferance_participants['uid']

i want to remove the object from my second array that has the same value

i want the output to be like

Array
(
    [0] => Array
        (
            [calleridnum] => 1
            [test] => yay
        )


    [2] => Array
        (
            [uid] => 2
            [test] => test
            [dit] => wew
        )

)

1 Answer 1

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);

Or if you don't want to change the $conferance_participants array then do

$result = array();
foreach ($conferance_participants as $key => $cp) {
    if ($cp['uid'] != $participants['calleridnum'])
        $result[] = $cp;
}
$result[] = $participants;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.