PHP array_diff not working

I am trying to use array_diff like this. Here are my two array outputs:

List 1 Exit

Array ([0] => 0022806 ) 

List 2 Exit

 Array ([0] => 0022806 [1] => 0023199 ) 

Php

 $diff = array_diff($list_1, $list_2); print "DIFF: " . count($diff) ."<br>"; print_r($diff); 

Exit:

 DIFF: 0 Array ( ) 

Any idea what I'm doing wrong?

+7
source share
4 answers

The order of the arguments in array_diff () is important

Returns an array containing all the entries from array1 that are not present in any of the other arrays

+13
source

to try

 $diff = array_merge(array_diff($list_1, $list_2), array_diff($list_2, $list_1)); print "DIFF: " . count($diff) ."<br>"; print_r($diff); 
+5
source

In the documentation, the values ​​of the second array are subtracted from the first. Or, in another way, you start with the first array, and then delete all the values ​​that appear in the second array. This will correctly give the empty array that you see above

You might want to play with the intersection , which may help you get what you want.

+1
source

From the docs :

Returns an array containing all entries from array1 that are not present in any of the other arrays.

If you only want to check if they match, you can use $list1 == $list_2

0
source

All Articles