title: Creating Multidimensional Nested Array from MySQL Result with Duplicate Values (PHP)
body: <p>I currently am pulling menu data out of our database using the PDO fetchAll() function. Doing so puts each row of the query results into an array in the following structure:</p>
  
  <pre><code>Array ( 
          [0] =&gt; Array ( 
                         [MenuId] =&gt; mmnlinlm08l6r7e8ju53n1f58 
                         [MenuName] =&gt; Main Menu 
                         [SectionId] =&gt; eq44ip4y7qqexzqd7kjsdwh5p 
                         [SubmenuName] =&gt; Salads &amp; Appetizers
                         [ItemName] =&gt; Tomato Salad
                         [Description] =&gt; Cucumbers, peppers, scallions and cured tuna
                         [Price] =&gt; $7.00) 
          [1] =&gt; Array ( 
                         [MenuId] =&gt; mmnlinlm08l6r7e8ju53n1f58 
                         [MenuName] =&gt; Main Menu 
                         [SectionId] =&gt; xlkadsj92laada9082lkas 
                         [SubmenuName] =&gt; Entrees 
                         [ItemName] =&gt; Portabello Carpaccio
                         [Description] =&gt; Dried tomatoes, pin nuts, mahon cheese
                         [Prices] =&gt; $18.00)
   )                      
                         ...etc.
  </code></pre>
  
  <p>For parsing reasons, I would like to have the array appear in a nested structure with no duplicate values:</p>
  
  <pre><code>Array ( 
            [MenuName] =&gt; Main Menu
            [MenuId] =&gt; mmnlinlm08l6r7e8ju53n1f58 
            [Section] =&gt;  Array ( 
                                  [SectionId] =&gt; eq44ip4y7qqexzqd7kjsdwh5p 
                                  [SubmenuName] =&gt; Salads &amp; Appetizers
                                  [Items] =&gt; Array (
                                                      [ItemName] =&gt; Tomato Salad
                                                      [Description] =&gt; Cucumbers, peppers, scallions and cured tuna
                                                      [Prices] =&gt; Array (
                                                                          [PriceId] =&gt; xksjslkajiak1
                                                                          [Price] =&gt; $7.00)
                                                    ) 
  
                                 [SectionId] =&gt; xlkadsj92laada9082lkas
                                 [SubmenuName] =&gt; Entrees
                                 [Items] =&gt; Array (                           
                                                     [ItemName] =&gt; Portabello Carpaccio
                                                     [Description] =&gt; Dried tomatoes, pin nuts, mahon cheese
                                                     [Prices] =&gt; Array (
                                                                          [PriceId =&gt; alkadh29189s09
                                                                          [Price] = $8.00)
                                                    )
                                 )
  )
  </code></pre>
  
  <p>As a n00b programmer, I've been racking my brain for the last day trying to figure out how to create this new, multidimensional array. It seems like I may have to use a couple of nested foreach statements and references, but I've had a hard time getting anything to work. </p>
  
  <p>Does anyone know how I can go about doing so?</p>