Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare two arrays based on the first N elements of the array PHP
    primarykey
    data
    text
    <p>I am trying to turn compare two arrays based on the first three elements of each array. I will then use <code>array_udiff</code> to find elements in the first original array that arent in the second original array. Here is my code and current outputs</p> <pre><code>function udiffanswers($a,$b){ $slicea = array_slice($a,0,3); $sliceb = array_slice($b,0,3); print_r($slicea); print_r($sliceb); if($slicea == $sliceb) { return 0; }else{ return -1; } } $diffinanswers = array_udiff($row ,$answers, 'udiffanswers'); echo "diff results \n"; print_r($diffinanswers); </code></pre> <p>THIS IS MY INPUT</p> <pre><code> answers sqlite results Array ( [0] =&gt; Array ( [aid] =&gt; 432267 [qid] =&gt; 0 [sid] =&gt; 1 [freetext] =&gt; [a] =&gt; Dog [b] =&gt; null 1 [c] =&gt; null 2 [d] =&gt; null 3 [e] =&gt; null 4 [f] =&gt; null 5 [g] =&gt; null 6 [h] =&gt; null 7 [i] =&gt; null 8 [j] =&gt; null 9 [type] =&gt; Multiple Choice [location] =&gt; 37.334709,-122.034111 ) [1] =&gt; Array ( [aid] =&gt; 1 [qid] =&gt; 0 [sid] =&gt; 1 [freetext] =&gt; [a] =&gt; Dog [b] =&gt; null 1 [c] =&gt; null 2 [d] =&gt; null 3 [e] =&gt; null 4 [f] =&gt; null 5 [g] =&gt; null 6 [h] =&gt; null 7 [i] =&gt; null 8 [j] =&gt; null 9 [type] =&gt; Multiple Choice [location] =&gt; 37.334709,-122.034111 ) ) </code></pre> <p>answers mysqli results </p> <pre><code> Array ( [0] =&gt; Array ( [aid] =&gt; 42 [qid] =&gt; 0 [sid] =&gt; 1 [freetext] =&gt; [a] =&gt; dog [b] =&gt; [c] =&gt; [d] =&gt; [e] =&gt; [f] =&gt; [g] =&gt; [h] =&gt; [i] =&gt; [j] =&gt; [type] =&gt; [location] =&gt; ) [1] =&gt; Array ( [aid] =&gt; 432267 [qid] =&gt; 0 [sid] =&gt; 1 [freetext] =&gt; [a] =&gt; Dog [b] =&gt; null 1 [c] =&gt; null 2 [d] =&gt; null 3 [e] =&gt; null 4 [f] =&gt; null 5 [g] =&gt; null 6 [h] =&gt; null 7 [i] =&gt; null 8 [j] =&gt; null 9 [type] =&gt; Multiple Choice [location] =&gt; 37.334709,-122.034111 ) [2] =&gt; Array ( [aid] =&gt; 432267 [qid] =&gt; 0 [sid] =&gt; 2 [freetext] =&gt; [a] =&gt; dog [b] =&gt; [c] =&gt; [d] =&gt; [e] =&gt; [f] =&gt; [g] =&gt; [h] =&gt; [i] =&gt; [j] =&gt; [type] =&gt; [location] =&gt; ) [3] =&gt; Array ( [aid] =&gt; 432267 [qid] =&gt; 2 [sid] =&gt; 1 [freetext] =&gt; [a] =&gt; dog [b] =&gt; [c] =&gt; [d] =&gt; [e] =&gt; [f] =&gt; [g] =&gt; [h] =&gt; [i] =&gt; [j] =&gt; [type] =&gt; [location] =&gt; ) ) </code></pre> <p>THIS IS THE OUTPUT(but should only contain array[1])</p> <pre><code> [0] =&gt; Array ( [aid] =&gt; 432267 [qid] =&gt; 0 [sid] =&gt; 1 [freetext] =&gt; [a] =&gt; Dog [b] =&gt; null 1 [c] =&gt; null 2 [d] =&gt; null 3 [e] =&gt; null 4 [f] =&gt; null 5 [g] =&gt; null 6 [h] =&gt; null 7 [i] =&gt; null 8 [j] =&gt; null 9 [type] =&gt; Multiple Choice [location] =&gt; 37.334709,-122.034111 ) [1] =&gt; Array ( [aid] =&gt; 1 [qid] =&gt; 0 [sid] =&gt; 1 [freetext] =&gt; [a] =&gt; Dog [b] =&gt; null 1 [c] =&gt; null 2 [d] =&gt; null 3 [e] =&gt; null 4 [f] =&gt; null 5 [g] =&gt; null 6 [h] =&gt; null 7 [i] =&gt; null 8 [j] =&gt; null 9 [type] =&gt; Multiple Choice [location] =&gt; 37.334709,-122.034111 ) ) </code></pre> <p>but it is. Im pretty sure the udiff function is not correct but cant figure it out. I only want the unique ones in the sqlite array to be output</p>
    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