title: how to compare two arrays and find the count of match elements
body: <p>i have two arrays i.e<pre><code>$ar1=array("Mobile","shop","software","hardware");</code></pre>and<pre>$arr2=arry("shop","Mobile","shop","software","shop")</pre>
   i want to compare the elements of arr2 to arr1 i.e</p>
  
  <pre>
      foreach($arr2 as $val)
      { 
          if(in_array($val, $arr1))
          {    
              //mycode to insert data into mysql table
  
              variable++;  // here there should be a variable that must be increamented when ever match found in $arr2 so that it can be saved into another table.
          }
           $query="update table set shop='$variable',Mobile='$variable'.......";
       }
  </pre>
  
  <p>the $variable should be an integer value so that for later use i can use this variable(shop i.e in this example its value should be 3) to find the match.</p>
  
  <p><br />
  My question is how can i get the variable that will increamented each time match found.</p>