title: To rearrange structure of multi dimensional array
body: <pre><code>array1:
  Array
  (
     "Page change" =&gt; Array
          (
             Array("parent_id" =&gt;,"access_id" =&gt; 1),
             Array("parent_id" =&gt;,"access_id" =&gt; 2),
             Array("parent_id" =&gt;2,"access_id" =&gt;3),
             Array("parent_id" =&gt;2,"access_id" =&gt;4),
             Array("parent_id" =&gt;,"access_id" =&gt;5),
             Array("parent_id" =&gt;5,"access_id" =&gt;6),
          )
  
     "Roles" =&gt; Array
          (
              Array("parent_id" =&gt;5,"access_id" =&gt;7),
              Array("parent_id" =&gt;,"access_id" =&gt;8),
          )
  )
  
  Array2:
  Array
  (
      [Page change] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [parent_id] =&gt; 
                      [access_id] =&gt; 1
                  )
  
              [1] =&gt; Array
                  (
                      [parent_id] =&gt; 
                      [access_id] =&gt; 2
                      [sub]=&gt;array(                        
                          [0]=&gt;Array
                              (
                                  [parent_id] =&gt; 2
                                  [access_id] =&gt; 3
                              )
                          [1] =&gt; Array
                              (
                                  [parent_id] =&gt; 2
                                  [access_id] =&gt; 4
                              )
                      )
                  )           
  
              [2] =&gt; Array
                  (
                      [parent_id] =&gt; 
                      [access_id] =&gt; 5
                      [sub]=&gt;array(
                          [0] =&gt; Array
                          (
                              [parent_id] =&gt; 5
                              [access_id] =&gt; 6
                          )
  
                      )
                  )           
  
          )
  
      [Roles] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [parent_id] =&gt; 
                      [access_id] =&gt; 7
                  )
  
              [1] =&gt; Array
                  (
                      [parent_id] =&gt; 
                      [access_id] =&gt; 8
                  )
  
          )
  )
  </code></pre>
  
  <p>I am struggling to change the structure of an array.My result array is like structure array one in my code.  I need to change that like array two using parent_id and access_id in first array.How can i possibly rearrange this multi-dimensional array</p>
  
  <p>If need add "sub" key in every inner arrays.</p>
  
  <p>Thanks for the help  in advance</p>