title: How to use the array intersect method to match two values within 2 sets of arrays
body: <p>I have this query:</p>
  
  <pre><code>$subcommon= MyModel::selectRaw('subjectlist_id, count(subjectlist_id) AS aggregate')
   -&gt;whereIn('user_id', [Auth::id(), $user-&gt;id])
  -&gt;groupBy('subjectlist_id')  
  -&gt;having('aggregate','&gt;',1)
  -&gt;get();
  </code></pre>
  
  <p>which gives this query result:</p>
  
  <pre><code>{"subjectlist_id":1,"aggregate":2} {"subjectlist_id":3,"aggregate":2}
  </code></pre>
  
  <p>I also have this query:</p>
  
  <pre><code>$values = Mysecondmodel::where('user_id', Auth::id())
                           -&gt;first(); 
  </code></pre>
  
  <p>which gives this result:</p>
  
  <pre><code>{"id":1,"subjectlist_id":1, "article_id":4}
  </code></pre>
  
  <p>Because im finding it way too difficult to join these two models i've decided to output them as arrays so I would like at least 1 matching value for <code>subjectlist_id</code> as a condition for it to execute the query I've displayed at the bottom. I'm assuming it's the <code>arrayintersect</code> method however im unsure how to use it.</p>
  
  <pre><code>$values = Mysecondmodel::where('user_id', Auth::id())
                             -&gt;first(); 
  </code></pre>
  
  <p>I have this so far:</p>
  
  <pre><code> $subcommonarray = (array) $subcommon;
  
  $valuesarray = (array) $values;
  
  $a = $subcommonarray;
  $b = $valuesarray;
  $c = array_intersect_key($a, $b);
  
  if (count($c) &gt; 0) {
  
  
     $newquery = Mysecondmodel::where(user_id, Auth::id())
   -&gt;first(); 
  
  }
  </code></pre>
  
  <p>But this I think is comparing the keys and not the values. How do I match the values and and the key together?</p>