phparraysfilterparametersarray-difference

Does order of input arrays matter when calling array_diff()?


I'm trying to find the difference in 2 arrays.

$inven_old = array(1,2,3,4); 
$inven_new = array(1,2,3,4,5); 
$result = array_diff($inven_old, $inven_new); 
print_r($result);

Why is the outcome nothing?

Shouldn't it be "5" ?

If not, how can I do what I'm trying to do?


Solution

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

    http://php.net/manual/en/function.array-diff.php

    array_diff() gives the result of subtracting all arrays except the first, from the first. Thus, things which are in the second array but not the first won't show up. (In other words, it's not the symmetric difference.)