Merge all child values back into the parent multidimensional array php

I have a multidimensional array and i need to merge all the child values back into its parent.

Say i have an array like this:

array(2) {

      [XY] =>
      array(3) {
                [A]=> 20
                [B]=> 30
                [2]=>
                array(2) {
                          [0]=> 1
                          [1]=> 2
                         }
               }
      [YZ] =>
      array(3) {
                [A]=> 60
                [B]=> 50
                [2]=>
                array(2) {
                          [0]=> 3
                          [1]=> 4
                         }
               }
}

and i want an output like this:

array(2) {

      [XY] =>
      array(4) {

                [A]=> 20
                [B]=> 30
                [2]=> 1
                [3]=> 2  
               }
      [YZ] =>
      array(4) {

                [A]=> 60
                [B]=> 50
                [2]=> 3
                [3]=> 4                             
               }
}

How can I do this?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s