title: Array restructure in PHP
body: <p>I have a php array that looks like this:</p>
  
  <pre><code>    Array
      (
         [0] =&gt; Array
                (
                  [0] =&gt; name_first
                  [1] =&gt; name_second
                  [2] =&gt; age
                )
  
         [1] =&gt; Array
                (
                  [0] =&gt; firstname1
                  [1] =&gt; surname1
                  [2] =&gt; age1
                )
  
         [2] =&gt; Array
                (
                  [0] =&gt; firstname2
                  [1] =&gt; surname2
                  [2] =&gt; age2
                )
      )
  </code></pre>
  
  <p>and I want to use the first three values (they do change) and if there is an underscored one (like the name_first and name_second in this example), re-structure the array into this:</p>
  
  <pre><code>    Array
      (
        [0] =&gt; Array
               (
                 [name] =&gt; Array
                           (
                             [first] =&gt; firstname1
                             [second] =&gt; surname1
                           )
                 [age] =&gt; age1
               )
  
        [1] =&gt; Array
               (
                 [name] =&gt; Array
                           (
                             [first] =&gt; firstname2
                             [second] =&gt; surname2
                           )
                 [age] =&gt; age2
               )
      )
  </code></pre>
  
  <p>I have been working on this for 2 days now but I am having trouble coming up with a solution to this so my question is: <b>How can I achieve this in an efficient way?</b></p>