Note that there are some explanatory texts on larger screens.

plurals
  1. POBug in array_uintersect?
    text
    copied!<pre><code>&lt;? function filterIdenticalEntriesCallback($a, $b) { echo "&lt;tr&gt;&lt;td&gt;{$a['file']}&lt;/td&gt;&lt;td&gt;{$b['file']}&lt;/td&gt;&lt;td&gt;{$a['md5']}&lt;/td&gt;&lt;td&gt;{$b['md5']}&lt;/td&gt;&lt;/tr&gt;"; if ( (strcmp($a['file'], $b['file']) == 0 ) &amp;&amp; ( strcmp($a['md5'],$b['md5']) == 0)){ return 0; } return 1; } $vieja = array( array('file' =&gt; 'a', 'md5' =&gt; '1'), //cambia array('file' =&gt; 'b', 'md5' =&gt; '2'), //igual array('file' =&gt; 'c', 'md5' =&gt; '3'), //igual array('file' =&gt; 'd', 'md5' =&gt; '4'), //igual ); $nueva = array( array('file' =&gt; 'a', 'md5' =&gt; '2'), //cambia array('file' =&gt; 'b', 'md5' =&gt; '2'), //igual array('file' =&gt; 'c', 'md5' =&gt; '3'), //igual array('file' =&gt; 'd', 'md5' =&gt; '4'), //igual ); echo "&lt;table&gt;"; $ignorar = array_uintersect($nueva, $vieja, 'filterIdenticalEntriesCallback'); echo "&lt;/table&gt;"; echo "&lt;pre&gt;"; print_r($ignorar); echo "&lt;/pre&gt;"; ?&gt; </code></pre> <p>OUTPUT</p> <pre><code>b a 2 2 b c 2 3 d b 4 2 a c 2 3 b a 2 1 b c 2 3 d b 4 2 a c 1 3 c c 3 3 c a 3 2 a a 2 1 a b 2 2 a d 2 4 Array ( [2] =&gt; Array ( [file] =&gt; c [md5] =&gt; 3 ) ) </code></pre> <p>I cant understand why this code doesn't produce the correct output which should be an array with "B", "C" and "D" elements, because only "A" element is different from $vieja to $nueva...</p> <p>if I make both "A" elements equals the output is ok....</p> <p><em>EDIT:</em></p> <pre><code>function filterIdenticalEntriesCallback($a, $b) { echo "&lt;tr&gt;&lt;td&gt;{$a['file']}&lt;/td&gt;&lt;td&gt;{$b['file']}&lt;/td&gt;&lt;td&gt;{$a['md5']}&lt;/td&gt;&lt;td&gt;{$b['md5']}&lt;/td&gt;&lt;/tr&gt;"; if (strcmp($a['file'], $b['file']) == 0 ){ if ( strcmp($a['md5'],$b['md5']) == 0) return 0; else return 1; } else return -1; </code></pre> <p>}</p> <p>Using this callback is working ok, but I still dont understand why... what -1 and 1 callback results means to the function? I mean, I need only equal values... wich are when callback return 0... I don't need other cases...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload