title: In PHP, is there a function that returns an array made up of the value of a key from an array of associative arrays?
body: <p>I'm sure this question has been asked before, my apologies for not finding it first.</p>
  
  <p>The original array:</p>
  
  <pre><code>[0] =&gt; Array
      (
          [categoryId] =&gt; 1
          [eventId] =&gt; 2
          [eventName] =&gt; 3
          [vendorName] =&gt; 4
      )
  
  [1] =&gt; Array
      (
          [categoryId] =&gt; 5
          [eventId] =&gt; 6
          [eventName] =&gt; 7
          [vendorName] =&gt; 8
      )
  
  [2] =&gt; Array
      (
          [categoryId] =&gt; 9
          [eventId] =&gt; 10
          [eventName] =&gt; 11
          [vendorName] =&gt; 12
      )
  </code></pre>
  
  <p>My hoped for result out of: print_r(get_values_from_a_key_in_arrays('categoryId', $array));</p>
  
  <pre><code>[0] =&gt; 1
  [1] =&gt; 5
  [2] =&gt; 9
  </code></pre>
  
  <p>I'm just looking for something cleaner than writing my own foreach based function. If foreach is the answer, I already have that in place.</p>
  
  <p><strong>Edit:</strong> I don't want to use a hard-coded key, I was just showing an example call to the solution. Thanks! ^_^</p>
  
  <p><strong>Quick Grab Solution for PHP 5.3:</strong></p>
  
  <pre><code>private function pluck($key, $data) {
      return array_reduce($data, function($result, $array) use($key) {
          isset($array[$key]) &amp;&amp; $result[] = $array[$key];
          return $result;
      }, array());
  }
  </code></pre>