How to remove array value from another array using PHP question

I want to check if there is any of the array values ​​from example 1 in example 2 and remove them from example 2, if any. How can I do this with PHP?

Example 1

Array ( [0] => 3 [1] => 5 ) 

Example 2

 Array ( [0] => 3 [1] => 3 [2] => 4 [3] => 4 [4] => 4 [5] => 3 [6] => 3 [7] => 3 [8] => 4 [9] => 4 [10] => 4 [11] => 3 ) 
+4
source share
3 answers

$example2 = array_diff($example2, $example1)

+9
source

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

array_diff calculates the difference between arrays. It returns an array containing all the records from the first array that are not present in any of the other arrays.

+7
source
 foreach($example2 as $key => $value) { foreach($example1 as $key1 => $value1) { if ($value1 == $value) { unset($example2[$key]) } } } 
0
source

All Articles