-2

I have a very simple PHP question.

Imagine i have two array :

[array1] {
[0] => zero
[1] => one
[2] => two
[3] => three 
}

and

[array2] {
[0] => zero
[1] => test1
[2] => test2
[3] => three 
}

I want to delete every value from the second array that is in the first one.

For example, from that two arrays at top, I want to have this below array ::

[array2] {
[0] => test1
[1] => test2
}

How can we do it in PHP ?

Thanks in advance.

Cab
  • 121
  • 1
  • 1
  • 12
  • @showdev this is **Not** duplicate ! just read quesion with examples again u will under stand. – Cab Aug 01 '14 at 21:13
  • 2
    They are both duplicates. All of these answer your question. Please explain how they are unsatisfactory or edit your question to help clarify. – showdev Aug 01 '14 at 21:14
  • @showdev You are right, i am sorry :X – Cab Aug 02 '14 at 08:34

1 Answers1

5

You can use array_diff():

$array2 = array_diff($array2, $array1);

Edit: Here is an example:

$array1 = array('zero', 'one', 'two', 'three');
$array2 = array('zero', 'test1', 'test2', 'three');

$array2 = array_diff($array2, $array1);
print_r($array2);
Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94