title: Sum values of multidimensional array by key without loop
body: <p>I have this:  </p>
  
  <pre><code>Array (
      [0] =&gt; Array ( [f_count] =&gt; 1 [uid] =&gt; 105 ) 
      [1] =&gt; Array ( [f_count] =&gt; 0 [uid] =&gt; 106 ) 
      [2] =&gt; Array ( [f_count] =&gt; 2 [uid] =&gt; 107 ) 
      [3] =&gt; Array ( [f_count] =&gt; 0 [uid] =&gt; 108 ) 
      [4] =&gt; Array ( [f_count] =&gt; 1 [uid] =&gt; 109 ) 
      [5] =&gt; Array ( [f_count] =&gt; 0 [uid] =&gt; 110 ) 
      [6] =&gt; Array ( [f_count] =&gt; 3 [uid] =&gt; 111 )
  )
  </code></pre>
  
  <p>What I need is: <code>7</code>", which is the the sum of the <code>f_count</code> column.</p>
  
  <p>I've been trying to figure this out for a couple hours. I thought <a href="http://php.net/manual/en/function.array-sum.php" rel="noreferrer"><code>array_sum()</code></a> would work, but not with a multidimensional array. So, I've tried figuring out how to isolate the <code>f_count</code>s by <code>unset()</code> or splicing or anything else, but every solution seems to involve a <code>foreach</code> loop. I've messed with <code>array_map</code>, <code>array_walk</code>, and others to no avail. I haven't found a function that works well with multidimensional arrays.</p>
  
  <p>I'm running PHP 5.4.</p>
  
  <p>Can someone please show me how to sum that column without a <code>foreach</code> loop?</p>
  
  <p>If it helps, the <code>f_count</code> values will never be higher than <code>100</code>, and the <code>uid</code> values will always be greater than <code>100</code>.</p>
  
  <hr>
  
  <p>Alternatively, if there's a way to run my query differently such that the array is not multidimensional, that would obviously work as well.</p>
  
  <pre><code>$query = "SELECT f_count, uid FROM users WHERE gid=:gid";
  ...
  $array = $stmt-&gt;fetchAll();
  </code></pre>
  
  <p>I'm using PDO.</p>