0

I have arrays that looks like this:

$array1 = array(
    '[email protected]' => array(
        'peter' => 'Smith',
    ),
    '[email protected]' => array(
        'john' => 'Smith',
    ),
    '[email protected]' => array(
        'louis' => 'Smith',
    ),
    '[email protected]' => array(
        'jane' => 'Smith',
    ),
);


$array2 = array(
    '0' => '[email protected]',
    '1' => '[email protected]',
);

How do I remove the array elements in array1 that match array2?

2 Answers 2

9

As simple as:

$diff = array_diff_key($array1, array_flip($array2));
Sign up to request clarification or add additional context in comments.

1 Comment

If I saw this reply I should haven't replied in this question (:
0

Quick and easy (but not as quick and easy as deceze's method, lol)

foreach ($array1 as $key => $value) {
    for ($i = 0; $i < count($array2); $i++) {
        if ($key == $array2[$i]) {
            unset($array1[$key]);
        }
    }
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.