I am using this piece of code to compare two php arrays, I got all matched items rightly but unfortunately i am not succeeding in getting non matched items. Here is my code.
<?php
$filter1 = "blueberries,abc,cornstarch,sugar";
$cval = strtoupper($filter1);
$parts1 = explode(',',$cval);
$filter2 = "water,blueberries,sugar,cornstarch";
$values = strtoupper($filter2);
$parts2 = explode(',', $values);
$m=0;
$nm=0;
for($i = 0; $i< count($parts1); $i++)
{
for($j = 0; $j< count($parts2); $j++)
{
if($parts1[$i] == $parts2[$j])
{
$m++;
$p[] = $parts1[$i];
}
else{
$nm++;
$q[] = $parts1[$i];
}
}
}
echo $m;
echo "<br />";
echo $nm;
echo "<br />";
print_r($p);
echo "<br />";
print_r($q);
?>
Can someone help me sorting out this problem, As i dont want to use builtin array comparison functions.
array_interesectandarray_diff