Looking for a slicker way of rebuilding this array
<p>I have a data result being returned from my database with multiple rows. The problem I'm having is that I only need a single row for some items and the multiple rows for others and without doing multiple database queries for every item that is needed, I thought I'd rebuild the data array.</p>

<p>What I am ultimately after is to use each item in the array as a string. If the last two items, product and location have multiple rows then I need them returned as strings.</p>

<p>What would be the best way to handle this?</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [cid] =&gt; one line
            [model] =&gt; one line
            [mfgr] =&gt; one line
            [color] =&gt; one line
            [orderid] =&gt; one line
            [product] =&gt; many lines
            [location] =&gt; many lines
        )
    [1] =&gt; Array
        (
            .. repeats for as many rows as were found
        )
)
</code></pre>

<hr>

<p>Let me rephrase this question. The array that you see above is the array that is produced from my foreach. Array key [0] holds all of the data from my result. Array key[1] simply repeats the data. I need single rows for columns 1-5. Columns 6 &amp; 7 are where I need multiple rows, hence the repeating array keys.</p>

<p>If I had to rebuild this array that way I need, it would look something like this:</p>

<pre><code>Array
(
    [single] =&gt; Array
        (
            [cid] =&gt; one line
            [model] =&gt; one line
            [mfgr] =&gt; one line
            [color] =&gt; one line
            [orderid] =&gt; one line

            [product] =&gt; Array
              (
                    [0] =&gt; many lines
                    [1] =&gt; many lines
              )
            [location] =&gt; Array
              (
                    [0] =&gt; many lines
                    [1] =&gt; many lines
              )
        )
)
</code></pre>
