title: Get the difference between two arrays in Laravel
body: <p>The <code>$category</code> variable will either hold values (i.e. tags) that are already available in the <code>tags</code> table, or the user can enter new tags in this variable , or both.</p>
  
  <p>Following is the query that brings tags if they are available in the <code>tags</code> table:</p>
  
  <pre class="lang-php prettyprint-override"><code>$TagNames = DB::table('tags')
                      -&gt;whereIn('t_name', $category)                  
                      -&gt;pluck('t_name'); 
  </code></pre>
  
  <p>The output of TagNames :</p>
  
  <pre class="lang-php prettyprint-override"><code>array(2) { [0]=&gt; string(7) "Zamalek" [1]=&gt; string(4) "Ahly" }
  </code></pre>
  
  <p>Below is the <code>$category</code> variable that will hold all the tags, regardless they are new tags entered by  the user, or existing ones.</p>
  
  <pre class="lang-php prettyprint-override"><code>$category = $request-&gt;get('catBox');
  </code></pre>
  
  <p>Output of <code>$category</code> (with two additional new tags) :</p>
  
  <pre class="lang-php prettyprint-override"><code>array(4) { [0]=&gt; string(7) "Zamalek" [1]=&gt; string(4) "Ahly" [2]=&gt; string(5) "Gouna" [3]=&gt; string(8) "Pyramids" }
  </code></pre>
  
  <p>The question is : How can I compare both <code>arrays</code> and get only the difference (i.e. "Gouna" and "pyramids" in this case) in a new array ?</p>