2 days ago I asked this question ( I am confused about the problem of how to use array_udiff ).
I apologize to discuss this issue again.
Although I have a solution to the problem, but I'm still confused on this issue:
demo1:
function myfunction($v1,$v2) { if ($v1===$v2) { return 0; } return 1; } $a1=array("a"=>"Cat","b"=>"Dog","c"=>"Horse"); $a2=array(1=>"Cat",2=>"Dog",3=>"Fish"); print_r(array_udiff($a1,$a2,"myfunction"));
output:
Array ( [c] => Horse )
demo2:
function myfunction($v1,$v2) { if ($v1===$v2) { return 0; } return 1; } $a1 = array(1,2,3,4,5); $a2 = array(1,6,3,4,5); print_r(array_udiff($a1,$a2,"myfunction"));
I expect this to return:
Array ( [0] => 2 )
but conclusion:
Array ( [0] => 1 [1] => 2 [2] => 3 [4] => 5 )
Yes, I know, I need according to the php manual,
demo3:
function myfunction($v1,$v2) { if ($v1 < $v2) { return -1; } elseif ($v1 > $v2) { return 1; } else { return 0; } } $a1 = array(1,2,3,4,5); $a2 = array(1,6,3,4,5); print_r(array_udiff($a1,$a2,"myfunction"));
output:
Array ( [1] => 2 )
What I'm confused about is that demo1 is fine.