PHP:查找值的数组差异[重复]

This question already has an answer here:

I have two pretty big arrays with email addresses in them.

$oldmail and $newmail.

Both looks like this:

[0] => some@email.com
[1] => some1@email.com
[2] => some2@email.com
...

I want to find all the email values in $newmail that does not exist anywhere in $oldmail.

I think this should work:

foreach ($oldmail as $key => $value) 
{
    foreach ($newmail as $key2 => $value2) 
    {
        if ($value == $value2) 
        {
            //do nothing..
        }
        else
        {
            echo $value2;
        }
    }
}

But it is way to resource heavy with big lists.

Is there another more effecient way I can do this?

</div>

PHP code demo

<?php
$a1=array("red","green","blue","yellow");
$a2=array("red","green","blue");

$result=array_diff($a1,$a2);
print_r($result);
?>

Use array_diff in PHP

$a1=array("some@email.com","some1@email.com");
$a2=array("some1@email.com","some2@email.com");
$result=array_diff($a2,$a1);
print_r($result);

Result:

Array ( [1] => some2@email.com ) 

array_diff() is right choice. It doesn't only matches by index as you mentioned in your comment. It compares all values.

Give this a shot:

$result=array_diff($newmail,$oldmail);
print_r($result);