Recently I've come across a question about merging multiple associative arrays into one.
Following is part of my code
//The Arrays ( Top 8 from the list )
$arr1["XMLResultColumn"]["1"]["Series"] = "Column1";
$arr2["XMLResultColumn"]["1"]["Series"] = "Column2";
$arr3["XMLResultColumn"]["1"]["Categories"] = "Column3";
$arr4["XMLResultColumn"]["1"]["Values"] = "Column4";
$arr5["XMLResultColumn"]["1"]["SecondaryValues"] = "Column5";
$arr6["XMLResultColumn"]["2"]["Series"] = "Column1";
$arr7["XMLResultColumn"]["2"]["Series"] = "Column2";
$arr8["XMLResultColumn"]["2"]["Categories"] = "Column3";
I have tried grouping them up using array_merge_recursive
inside a loop like the following
$arr9 = array();
for( $i = 1 ; $i < 9 ; $i++ ) {
$arr9 = array_merge_recursive( $arr9 , ${"arr$i"} );
}
The $arr9
outputs as following:
Array ( [XMLResultColumn] => Array ( [1] => Array ( [Series] => Column1 ) [2] => Array ( [Series] => Column2 ) [3] => Array ( [Categories] => Column3 ) [4] => Array ( [Values] => Column4 ) [5] => Array ( [SecondaryValues] => Column5 ) [6] => Array ( [Series] => Column1 ) [7] => Array ( [Series] => Column2 ) [8] => Array ( [Categories] => Column3 ) ) )
I expected the result to be:
Array ( [XMLResultColumn] => Array ( [1] => Array ( [Series] => Array ( [0] => Column1 [1] => Column2 ) [Categories] => Array ( [0] => Colomn3 ) [Values] => Array ( [0] => Column4 ) [SecondaryValues] => Array ( [0] => Column5 ) ) [2] => Array ( [Series] => Array ( [0] => Column1 [1] => Column2 ) [Categories] => Array ( [0] => Colomn3 ) ) ) )
Is there any way to produce the expected output as above? Any help is appreciated!
Thank you for reading this question.