title: Why is my code making PDO return nested arrays?
body: <p>I'm sure I must be doing something wrong, but I can't seem to find an answer anywhere (at least neither in the documentation nor on SO as of yet). I am a beginner in PHP and SQL.</p>
  
  <p>I have this simple table called "mObject_has_media" with only two columns "media_idMedia" and "mObject_idmObject"</p>
  
  <p>When I try to query the table with this code,</p>
  
  <pre><code>public function selectMediaIds (MObject $object) {
      $medias = array ();
      $req = $this -&gt; _db -&gt; query ('SELECT media_idMedia FROM mObject_has_media WHERE mObject_idmObject = ' . $object -&gt; id ());
      while ($data = $req -&gt; fetch (PDO::FETCH_ASSOC)) {
          $medias[] = $data;
      }
      $req -&gt; closeCursor ();
      return $medias;
  }
  </code></pre>
  
  <p>the problem is this: when I var_dump the contents of the method's result, I get:</p>
  
  <pre><code>array (size=2)
    0 =&gt; 
      array (size=1)
        'media_idMedia' =&gt; string '52' (length=2)
    1 =&gt; 
      array (size=1)
        'media_idMedia' =&gt; string '53' (length=2)
  </code></pre>
  
  <p>I'd like to get rid of those nested arrays and just get something like:</p>
  
  <pre><code>array (size=2)
    0 =&gt; 'media_idMedia' =&gt; string '52' (length=2)
    1 =&gt; 'media_idMedia' =&gt; string '53' (length=2)
  </code></pre>
  
  <p>so I can simply run this array into a foreach loop right afterwards... I'm sure that this problem has everything to do with the fetch() method, but in spite of experimenting with different options, I haven't been able to get the desired behavior.</p>
  
  <p>A similar question (I think) was asked here: <a href="https://stackoverflow.com/questions/7682691/pdofetch-assoc-does-not-return-the-correct-table-columns">PDO::FETCH_ASSOC Does not return the correct table columns</a> but the answer mentioned the Zend framework, and I am NOT using any framework at all, this is just vanilla PHP.</p>