How does array_udiff() work?
<p>Here's the code, it's very simple:</p>

<pre><code>&lt;?php
$tab = array (
    (object)array( 'id' =&gt; 1,),
    (object)array( 'id' =&gt; 4,),
    (object)array( 'id' =&gt; 12,),
    (object)array( 'id' =&gt; 22,),
    (object)array( 'id' =&gt; 25,),
);

$tab_json = array (
    (object)array( 'id' =&gt; 1,),
    (object)array( 'id' =&gt; 4,),
    (object)array( 'id' =&gt; 12,),
    (object)array( 'id' =&gt; 22,),
    (object)array( 'id' =&gt; 25,),
    (object)array( 'id' =&gt; 2,),
);
$difference = array_udiff($tab_json, $tab, function($a, $b) {
    echo $a-&gt;id." &lt;-&gt; ".$b-&gt;id."\n";
    return (count(array_diff_assoc(get_object_vars($a), get_object_vars($b))))&gt;0;
});
?&gt;
</code></pre>

<p>Here's the output:</p>

<pre><code>12 &lt;-&gt; 4
12 &lt;-&gt; 1
12 &lt;-&gt; 22
12 &lt;-&gt; 25
2 &lt;-&gt; 12
4 &lt;-&gt; 25
4 &lt;-&gt; 1
22 &lt;-&gt; 4
25 &lt;-&gt; 1
12 &lt;-&gt; 4
12 &lt;-&gt; 1
12 &lt;-&gt; 22
25 &lt;-&gt; 12
4 &lt;-&gt; 22
1 &lt;-&gt; 4
1 &lt;-&gt; 22
1 &lt;-&gt; 4
1 &lt;-&gt; 1
1 &lt;-&gt; 25
25 &lt;-&gt; 4
25 &lt;-&gt; 1
25 &lt;-&gt; 12
25 &lt;-&gt; 25
25 &lt;-&gt; 4
4 &lt;-&gt; 1
4 &lt;-&gt; 12
4 &lt;-&gt; 25
4 &lt;-&gt; 22
22 &lt;-&gt; 1
22 &lt;-&gt; 12
22 &lt;-&gt; 25
22 &lt;-&gt; 12
12 &lt;-&gt; 1
12 &lt;-&gt; 12
12 &lt;-&gt; 2
2 &lt;-&gt; 12
2 &lt;-&gt; 25
</code></pre>

<p>I don't understand how it's computed: look at <code>12</code>: it's compared more than 10 times (whereas, from what I understand, it should be compared no more than the number of elements of the second array), and moreover it's compared three times with <code>1</code>!</p>

<p>Tested on:</p>

<pre><code>PHP 5.3.9
PHP 5.3.2-1ubuntu4.14
</code></pre>
