title: How can I convert this M-N mysql array in this other array in PHP? (examples inside)
body: <p>Well, is pretty common to get an array like this in relations M-N in mysql:</p>
  
  <pre><code>[0]
  'book_id' =&gt; 1
  'title' =&gt; 'title'
  'author_id' =&gt; 1
  'author_name' =&gt; 'name1'
  
  [1]
  'book_id' =&gt; 1
  'title' =&gt; 'title'
  'author_id' =&gt; 2
  'author_name' =&gt; 'name2'
  </code></pre>
  
  <p>So, there is an elegant/easy way to convert this kind or arrays in something like this?</p>
  
  <pre><code>'book_id' =&gt; 1
  'title' =&gt; 'title'
  'authors' =&gt; array( 0 =&gt; array( 'author_id' =&gt; 1, 'author_name' =&gt; 'name1' ),
  1 =&gt; array( 'author_id' =&gt; 2, 'author_name' =&gt; 'name2' ) )
  </code></pre>
  
  <p>I don't find any script or combinations of functions that made this... and is pretty common, maybe I have not searched correctly.. don't know how to call the  problem...</p>
  
  <p>Any ideas or experiences?</p>
  
  <p>Thanks :)</p>
  
  <p>PS: I don't want to use GROUP BY + GROUP CONCACT in MySQL, I found that pretty ugly solution...</p>
  
  <p><strong>EDIT:</strong>
  I'm working in something generic, not only to solve this specific problem..</p>