Q:

PHP I have two arrays, I want to extract items from Array 1 if it's not already in Array 2

Like the title says, I have two arrays and I just want to get everything from the first array that's not already in the second array. How do I do this?

A:

Use array_diff:
$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);

print_r($result);

Result:

Array
(
    [1] => blue
)

See it working online: ideone

