title: How to count the number of occurrences in one array from the values of a second array in PHP?
body: <p>I have 2 arrays in PHP that look something like this:</p>
  
  <pre><code>$rows = array(11,12,14,14,11,13,12,11);
  $cols = array(1,2,1,2,2,2,1,1);
  </code></pre>
  
  <p>I need to combine these arrays in a way that tells how many of each <code>$cols</code> value is in each <code>$rows</code> value.</p>
  
  <p>So my result should look something like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [row] =&gt; 11
              [1] =&gt; 2 //the count of 1 cols for 11
              [2] =&gt; 1 //the count of 2 cols for 11
          )
  
      [1] =&gt; Array
          (
              [row] =&gt; 12
              [1] =&gt; 1
              [2] =&gt; 1
          )
  
      ...
  )
  </code></pre>
  
  <p>The values of $rows and $cols will change based upon the users input, they may even be strings.</p>
  
  <p><strong>Clarification:</strong></p>
  
  <p>The duplicates values come from the data. Think survey results or test questions. So question 11 had 2 people answer 1 and 1 person answer 2.</p>
  
  <p><strong>Question:</strong></p>
  
  <p>How do I count the number of occurrences of $cols in $rows and add the results into a multidimensional array?</p>