title: Create multidimensional array from database query in PHP
body: <p>I have a database with a number of entries with data like so:</p>
  
  <pre><code>id  number  data
  1   1       'tyfvib'
  2   1       'fgdhjjd'
  3   1       'gdgdhdj'
  4   2       'dgfhfh'
  5   2       'fghdhd'
  </code></pre>
  
  <p>So I have a unique ID and then a column with numbers and then a column with different strings.</p>
  
  <p>I then have a query like this:</p>
  
  <pre><code>$sql = "SELECT * FROM table";
  $stmt = DB::run($sql);
  while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)){
      $number= $row['number'];
      $data = $row['data'];
  }
  </code></pre>
  
  <p>I want to make a multidimensional associative array which would have first of all an array of the unique numbers and these would contain an array of the data associated with them.</p>
  
  <p>I had tried putting <code>$array[$number] = $data</code> inside the while loop but this obviously will just make an array where the only data associated with a number is the last one in the loop.</p>