title: Easiest way to remove Keys from a 2D Array?
body: <p>I have an Array that looks like this:</p>
  
  <pre><code>array(
    0 =&gt; array(
      'key1' =&gt; 'a',
      'key2' =&gt; 'b',
      'key3' =&gt; 'c'
    ),
    1 =&gt; array(
      'key1' =&gt; 'c',
      'key2' =&gt; 'b',
      'key3' =&gt; 'a'
    ),
    ...
  )
  </code></pre>
  
  <p>I need a function to get an array containing just a (variable) number of keys, i.e. reduce_array(array('key1', 'key3')); should return:</p>
  
  <pre><code>array(
    0 =&gt; array(
      'key1' =&gt; 'a',
      'key3' =&gt; 'c'
    ),
    1 =&gt; array(
      'key1' =&gt; 'c',
      'key3' =&gt; 'a'
    ),
    ...
  )
  </code></pre>
  
  <p>What is the easiest way to do this? If possible without any additional helper function like array_filter or array_map as my coworkers already complain about me using too many functions.</p>
  
  <p>The source array will always have the given keys so it's not required to check for existance.</p>
  
  <p>Bonus points if the values are unique (the keys will always be related to each other, meaning that if key1 has value a then the other key(s) will always have value b).</p>
  
  <p>My current solution which works but is quite clumsy (even the name is horrible but can't find a better one):</p>
  
  <pre><code>function get_unique_values_from_array_by_keys(array $array, array $keys)
  {
          $result = array();
          $found = array();
  
          if (count($keys) &gt; 0)
          {
                  foreach ($array as $item)
                  {
                          if (in_array($item[$keys[0]], $found)) continue;
                          array_push($found, $item[$keys[0]]);
                          $result_item = array();
                          foreach ($keys as $key)
                          {
                                  $result_item[$key] = $item[$key];
                          }
                          array_push($result, $result_item);
                  }
          }
          return $result;
  }
  </code></pre>
  
  <p><em>Addition</em>:<br>
  PHP Version is 5.1.6.</p>