I have been using this piece of code to compare two values, I am getting the matched items exactly, The only problem is with non matched items.
$filter1 = "red,green,blue,yellow";
$parts1 = explode(',', $filter1);
$filter2 = "red,green,blue";
$parts2 = explode(',', $filter2);
for($i=0; $i< count($parts1); $i++)
{
for($j=0; $j< count($parts2); $j++)
{
if(strpos($parts1[$i],$parts2[$j]) !== false)
{
$match[] = $parts1[$i];
}
else
{
$nomatch[] = $parts2[$j];
}
}
}
print_r($match);
echo "<br>";
print_r($nomatch);
And what i am getting as result is
Array ( [0] => red [1] => green [2] => blue )
Array ( [0] => green [1] => blue [2] => red [3] => blue [4] => red [5] => green [6] =>
red [7] => green [8] => blue )
Array 1 is giving the exact matched values but array 2 is giving absurd results instead of yellow.
array_diff()andarray_intersect()?array_udiffandarray_uintersectis the way to go (-: