Skip to content
Advertisement

difference between two arrays

I have following two arrays. I want the difference between these two arrays. That is, how can I find the values that do not exist in both arrays?

 $array1=Array ( [0] => 64 [1] => 98 [2] => 112 [3] => 92 [4] => 92 [5] => 92 ) ;
 $array2=Array ( [0] => 3 [1] => 26 [2] => 38 [3] => 40 [4] => 44 [5] => 46 [6] => 48 [7] => 52 [8] => 64 [9] => 68 [10] => 70 [11] => 72 [12] => 102 [13] => 104 [14] => 106 [15] => 92 [16] => 94 [17] => 96 [18] => 98 [19] => 100 [20] => 108 [21] => 110 [22] => 112);

Advertisement

Answer

Note: this answer will return the values in $array2 that are not present in $array1, it will not return the values in $array1 that are not in $array2.

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

array_diff()

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement