[ create a new paste ] login | about

Link: http://codepad.org/J6lmOUVO    [ raw code | output | fork ]

PHP, pasted on Oct 2:
<?php 

$filter1 = "red,green,blue,yellow";         
$parts1 = explode(',', $filter1);

$filter2 = "red,green,blue";        
$parts2 = explode(',', $filter2);

for($i=0; $i< count($parts1); $i++)
{
  $matched = false;
  for($j=0; $j< count($parts2); $j++)
  {
    if(strpos($parts1[$i],$parts2[$j]) !== false)
    {
      $match[] = $parts1[$i];
      $matched = true;
    }
  }
  if (!$matched)
  {
    $nomatch[] = $parts1[$i];
  }
}

print_r($match);
echo "<br>";
print_r($nomatch);


Output:
1
2
3
4
5
6
7
8
9
10
Array
(
    [0] => red
    [1] => green
    [2] => blue
)
<br>Array
(
    [0] => yellow
)


Create a new paste based on this one


Comments: