creating a multidimensional array from queries
<p>I'm having difficulty constructing a multidimensional array based on queries fetched from a mysql database.  The purpose is to prepare the result for json encoding.  Having problems here.</p>

<p>Structure I’m aiming for:</p>

<pre><code>Array ( 
    [68] =&gt; Array ( 
        [0] =&gt; Array ( 
            [id] =&gt; 64 
            [description] =&gt; yada, yada, yada... ) 
        [1] =&gt; Array ( 
            [id] =&gt; 65 
            [description] =&gt; yada, yada, yada...) 
        [2] =&gt; Array ( 
            [id] =&gt; 66 
            [description] =&gt; yada, yada, yada... ) ) 
    [69] =&gt; Array ( 
        [0] =&gt; Array ( 
            [id] =&gt; 64 
            [description] =&gt; yada, yada, yada... ) 
        [1] =&gt; Array ( 
            [id] =&gt; 65 
            [description] =&gt; yada, yada, yada...) 
        [2] =&gt; Array ( 
            [id] =&gt; 66 
            [description] =&gt; yada, yada, yada... ) ) 
...etc
)
</code></pre>

<p>From:</p>

<pre><code>//this is a list of unknown length
$array_ids = (68, 69, 70, etc... );   // or:

Array ( 
    [0] =&gt; 68 
    [1] =&gt; 69
    [2] =&gt; 70 
    [3] =&gt; 71 
    etc..  
)


//this is a known length 
$array_contents = ( array ( array ( [id], [description]) );  // or:

Array ( 
    [0] =&gt; Array ( 
        [id] =&gt; 64 
        [description] =&gt;yada, yada, yada... ) 
    [1] =&gt; Array ( 
        [id] =&gt; 65 
        [description] =&gt; yada, yada, yada... ) 
    [2] =&gt; Array ( 
        [id] =&gt; 66 
        [description] =&gt; yada, yada, yada... ) )
</code></pre>

<p>My attempt:</p>

<pre><code>foreach($array_ids as $row){
    $result = array($row=&gt;array());
    foreach($array_contents as $key =&gt; $value){
        $result [$row][$key] = $value;
    }
}
</code></pre>

<p>Result:</p>

<pre><code>Array ( 
    [68] =&gt; Array ( 
        [0] =&gt; Array ( 
            [id] =&gt; 64 
            [description] =&gt; yada, yada, yada... ) 
        [1] =&gt; Array ( 
            [id] =&gt; 65 
            [description] =&gt; yada, yada, yada...) 
        [2] =&gt; Array ( 
            [id] =&gt; 66 
            [description] =&gt; yada, yada, yada... ) ) 
</code></pre>

<p>)</p>

<p>...and that’s where it stops.  It doesn’t go on to the next row id of 69, 70, etc...</p>

<p>What am I doing wrong?</p>
