Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing array_udiff in php for multiple fields
    primarykey
    data
    text
    <p>Im trying to make a custom function for my script where it it checks one of the indexes of the two arrays and dependent on the custom function it returns all the rows not in both arrays. It has worked well for when i have to only check one value as such:</p> <pre><code>function udifflink($a, $b) { return $a['linkid'] - $b['linkid']; } //compare links array $diffinlinks = array_udiff($row, $surveys, 'udifflink'); echo "diff results \n"; print_r($diffinlinks); </code></pre> <p>but when i have arrays where i need to check two fields for combined equality (this is a database table where the primary key is two columns) it does not work as expected. I have tried multiple solutions but this is my most recent:</p> <pre><code>function udiffanswers($a, $b) { return $a['aid'].$a['sid'] - $b['aid'].$b['sid']; } </code></pre> <p>which does not exclude the places where both the aid and sid are the same</p> <pre><code>//array a [16] =&gt; Array ( [aid] =&gt; 16 [qid] =&gt; 16 [sid] =&gt; 16 [freetext] =&gt; adfadf [a] =&gt; adfadf [b] =&gt; adfadf [c] =&gt; adfadf [d] =&gt; adfadf [e] =&gt; adfadf [f] =&gt; adfadf [g] =&gt; adfadf [h] =&gt; adfadf [i] =&gt; adfadf [j] =&gt; adfadf [type] =&gt; adfadf [location] =&gt; adfadf ) //array b [17] =&gt; Array ( [aid] =&gt; 16 [qid] =&gt; 17 [sid] =&gt; 16 [freetext] =&gt; adfadf [a] =&gt; adfadf [b] =&gt; adfadf [c] =&gt; adfadf [d] =&gt; adfadf [e] =&gt; adfadf [f] =&gt; adfadf [g] =&gt; adfadf [h] =&gt; adfadf [i] =&gt; adfadf [j] =&gt; adfadf [type] =&gt; adfadf [location] =&gt; adfadf ) [18] =&gt; Array ( [aid] =&gt; 16 [qid] =&gt; 18 [sid] =&gt; 18 [freetext] =&gt; adfadf [a] =&gt; adfadf [b] =&gt; adfadf [c] =&gt; adfadf [d] =&gt; adfadf [e] =&gt; adfadf [f] =&gt; adfadf [g] =&gt; adfadf [h] =&gt; adfadf [i] =&gt; adfadf [j] =&gt; adfadf [type] =&gt; adfadf [location] =&gt; adfadf ) [19] =&gt; Array ( [aid] =&gt; 17 [qid] =&gt; 18 [sid] =&gt; 16 [freetext] =&gt; adfadf [a] =&gt; adfadf [b] =&gt; adfadf [c] =&gt; adfadf [d] =&gt; adfadf [e] =&gt; adfadf [f] =&gt; adfadf [g] =&gt; adfadf [h] =&gt; adfadf [i] =&gt; adfadf [j] =&gt; adfadf [type] =&gt; adfadf [location] =&gt; adfadf ) </code></pre> <p>18 and 19 arrays should be returned from above</p> <p>this is something else ive tried... not really sure how to get the result from multiple ifs...</p> <pre><code>function udiffanswers($a, $b) { if($a['aid'] - $b['aid']){ if($a['sid'] - $b['sid']){ return $a; } } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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