title: PHP - Count duplicate values within two dimensional array, then display only unique values with the count
body: <p>I've been working on this for a couple days now... and still haven't been able to achieve my desired results. Any help would on this would be greatly appreciated... thank you in advance.</p>
  
  <p>I have a multi-array stored in $log, which displays like this when you print_r($log):</p>
  
  <pre><code>   Array ( [0] =&gt; Array ( [0] =&gt; Red [1] =&gt; Steel ) 
             [1] =&gt; Array ( [0] =&gt; Red [1] =&gt; Wood ) 
             [2] =&gt; Array ( [0] =&gt; Blue [1] =&gt; Wood ) 
           )
  </code></pre>
  
  <p>Currently I have this:</p>
  
  <pre><code>$counts = $log;
  foreach ($log as $value) {
      foreach ($value as $k  =&gt; $v) {
          if (!isset($counts[$k])) $counts[$k] = array();
          if (!isset($counts[$k][$v])) $counts[$k][$v] = 0;
          $counts[$k][$v] += 1;
      }
  }
  
  foreach ($counts as $k =&gt; $v1) {
      foreach ($v1 as $v =&gt; $count) {
          echo "$v =&gt; $count &lt;br /&gt;";
      }
  }
  </code></pre>
  
  <p>Which Displays:</p>
  
  <pre><code>0 =&gt; Red 
  1 =&gt; Steel 
  Red =&gt; 2 
  Blue =&gt; 1 
  0 =&gt; Red 
  1 =&gt; Wood 
  Steel =&gt; 1 
  Wood =&gt; 2 
  0 =&gt; Blue 
  1 =&gt; Wood  
  </code></pre>
  
  <p>But I'm really looking to have an end result of:</p>
  
  <pre><code>&lt;h2&gt;Colors&lt;/h2&gt;
  Red =&gt; 2
  Blue =&gt; 1
  
  &lt;h2&gt;Materials&lt;/h2&gt;
  Steel =&gt; 1
  Wood =&gt; 2
  </code></pre>