title: MySQL and PHP - Efficiently get rows and arrays associated with each row
body: <p>I have two tables:</p>
  <h3>table1:</h3>
  <pre><code>ID | user | info
  ------------------
  1    1      data1
  2    1      data2
  3    2      data3
  </code></pre>
  <h3>table2:</h3>
  <pre><code>table1_id | array_info
  ------------------------
  1             a  
  1             b
  2             a
  3             d
  3             g
  3             m
  </code></pre>
  <p>How can I efficiently return the rows associated with a user such that I get info and an array of that ID's associated array_info?</p>
  <p>For instance, a query like &quot;select ID, info from table1 where user = 1&quot; but would also return [a,b] from table2 so that the result would be something like [1, data1, [a, b]] with the first row and [2, data2, [a]] with the second row. Similarly, &quot;...where user = 2&quot; should return something like [3, data3, [d, g, m]]. I don't think MySQL returns things quite like this, but perhaps PHP can smooth over the input of a left join? It seems wasteful to replicate all the data in info if MySQL returns a separate row for each array_info, but I'm not sure there's another way.</p>