PHP array_diff not working

前端 未结 4 495
孤街浪徒
孤街浪徒 2021-01-04 12:56

I\'m trying to use array_diff like so. Here are my two array outputs:

List 1 Output

Array ([0] => 0022806 ) 

List 2 Output

相关标签:
4条回答
  • 2021-01-04 13:37

    Per the documentation, the values of the second array are subtracted from the first one. Or, to put it another way, you start with the first array, and then remove all the values that appear in the second array. That would correctly yield an empty array that you see above

    You might want to play around with intersection, that might help you get what you want.

    0 讨论(0)
  • 2021-01-04 13:41

    The order of 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

    0 讨论(0)
  • 2021-01-04 13:42

    try;

    $diff = array_merge(array_diff($list_1, $list_2), array_diff($list_2, $list_1));
    
    print "DIFF: " . count($diff) ."<br>";
    print_r($diff);
    
    0 讨论(0)
  • 2021-01-04 13:42

    From the docs:

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

    If you only want to check whether they are the same, you can use $list1 == $list_2

    0 讨论(0)
提交回复
热议问题