title: Is there a way to fetch associative array grouped by the values of a specified column with PDO?
body: <p>For example, let's use some simple data set</p>
  
  <pre><code>+---------+------+------+------------+
  | name    | age  | sex  | position   |
  +---------+------+------+------------+
  | Antony  |   34 | M    | programmer |
  | Sally   |   30 | F    | manager    |
  | Matthew |   28 | M    | designer   |
  +---------+------+------+------------+
  </code></pre>
  
  <p>What we are trying to get is array organized this way</p>
  
  <pre><code>Array
  (
    [Antony] =&gt; Array
      (
        [age] =&gt; 34
        [sex] =&gt; M
        [position] =&gt; programmer
      )
  
    [Sally] =&gt; Array
      (
        [age] =&gt; 30
        [sex] =&gt; F
        [position] =&gt; manager
      )
  
    [Matthew] =&gt; Array
      (
        [age] =&gt; 28
        [sex] =&gt; M
        [position] =&gt; designer
      )
  )
  </code></pre>
  
  <p>As a rough approximation we can use</p>
  
  <pre><code>$pdo-&gt;query('SELECT * FROM employee')-&gt;fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
  </code></pre>
  
  <p>But as result we have unnecessary nesting level</p>
  
  <pre><code>Array
  (
      [Antony] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [age] =&gt; 34
                      [sex] =&gt; M
                      [position] =&gt; programmer
                  )
  
          )
  
      [Sally] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [age] =&gt; 30
                      [sex] =&gt; F
                      [position] =&gt; manager
                  )
  
          )
  
      [Matthew] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [age] =&gt; 28
                      [sex] =&gt; M
                      [position] =&gt; designer
                  )
  
          )
  
  )
  </code></pre>
  
  <p>I tried to get rid of this unnecessary nesting level by using callback function</p>
  
  <pre><code>$stmt-&gt;fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC|PDO::FETCH_FUNC, 'current');
  </code></pre>
  
  <p>But for some reasons It passes not </p>
  
  <pre><code>Array
    (
     [0] =&gt; Array
      (
          [age] =&gt; 34
          [sex] =&gt; M
          [position] =&gt; programmer
      )
    ) 
  </code></pre>
  
  <p>but just a bunch of scalars <code>34, 'M', 'programmer'</code> to callback function :(</p>
  
  <p>You can see it using such function as callback</p>
  
  <pre><code>function what_do_you_pass_me() {
  
    $numargs = func_num_args();
    $arg_list = func_get_args();
    for ($i = 0; $i &lt; $numargs; $i++) {
      echo "Argument $i is: " . $arg_list[$i] . "\n";
    };
    echo "\n\n";
  };
  </code></pre>
  
  <p>So is there a way to get desired resultset using <code>PDO::FETCH_*</code> modes without using <code>array_map('current', $result)</code> after fetching results ?</p>