I am trying to turn compare two arrays based on the first three elements of each array. I will then use array_udiff
to find elements in the first original array that arent in the second original array. Here is my code and current outputs
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
";
print_r($diffinanswers);
THIS IS MY INPUT
answers sqlite results
Array
(
[0] => Array
(
[aid] => 432267
[qid] => 0
[sid] => 1
[freetext] =>
[a] => Dog
[b] => null 1
[c] => null 2
[d] => null 3
[e] => null 4
[f] => null 5
[g] => null 6
[h] => null 7
[i] => null 8
[j] => null 9
[type] => Multiple Choice
[location] => 37.334709,-122.034111
)
[1] => Array
(
[aid] => 1
[qid] => 0
[sid] => 1
[freetext] =>
[a] => Dog
[b] => null 1
[c] => null 2
[d] => null 3
[e] => null 4
[f] => null 5
[g] => null 6
[h] => null 7
[i] => null 8
[j] => null 9
[type] => Multiple Choice
[location] => 37.334709,-122.034111
)
)
answers mysqli results
Array
(
[0] => Array
(
[aid] => 42
[qid] => 0
[sid] => 1
[freetext] =>
[a] => dog
[b] =>
[c] =>
[d] =>
[e] =>
[f] =>
[g] =>
[h] =>
[i] =>
[j] =>
[type] =>
[location] =>
)
[1] => Array
(
[aid] => 432267
[qid] => 0
[sid] => 1
[freetext] =>
[a] => Dog
[b] => null 1
[c] => null 2
[d] => null 3
[e] => null 4
[f] => null 5
[g] => null 6
[h] => null 7
[i] => null 8
[j] => null 9
[type] => Multiple Choice
[location] => 37.334709,-122.034111
)
[2] => Array
(
[aid] => 432267
[qid] => 0
[sid] => 2
[freetext] =>
[a] => dog
[b] =>
[c] =>
[d] =>
[e] =>
[f] =>
[g] =>
[h] =>
[i] =>
[j] =>
[type] =>
[location] =>
)
[3] => Array
(
[aid] => 432267
[qid] => 2
[sid] => 1
[freetext] =>
[a] => dog
[b] =>
[c] =>
[d] =>
[e] =>
[f] =>
[g] =>
[h] =>
[i] =>
[j] =>
[type] =>
[location] =>
)
)
THIS IS THE OUTPUT(but should only contain array[1])
[0] => Array
(
[aid] => 432267
[qid] => 0
[sid] => 1
[freetext] =>
[a] => Dog
[b] => null 1
[c] => null 2
[d] => null 3
[e] => null 4
[f] => null 5
[g] => null 6
[h] => null 7
[i] => null 8
[j] => null 9
[type] => Multiple Choice
[location] => 37.334709,-122.034111
)
[1] => Array
(
[aid] => 1
[qid] => 0
[sid] => 1
[freetext] =>
[a] => Dog
[b] => null 1
[c] => null 2
[d] => null 3
[e] => null 4
[f] => null 5
[g] => null 6
[h] => null 7
[i] => null 8
[j] => null 9
[type] => Multiple Choice
[location] => 37.334709,-122.034111
)
)
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