I am struggling with a data structure in PHP. I'm trying to use array_merge_recursive to condense an array by like keys and then grab all values instead of having them overwritten. This is why I chose array_merge_recursive instead of array_merge.
My array is something similar to:
Array
(
[0] => Array
(
[App] => APP1
[Type] => DB
)
[1] => Array
(
[App] => APP1
[Type] => WEBSITE
)
[2] => Array
(
[App] => APP2
[Type] => IOS
)
)
I was expecting array_merge_recursive to combine like keys and then group the other elements into arrays however this is not the behavior I am seeing.
I am hoping to get an array like the following:
Array
(
[0] => Array
(
[App] => APP1
[Type] => Array
(
[0] => DB
[1] => WEBSITE
)
)
[1] => Array
(
[App] => APP2
[Type] => IOS
)
)
not the behavior I am seeingin your result you moveDBfrom keyTypeto an subarray with key0. Same forWEBSITE. How do you thingarray_merge_recursiveworks? And try to explain the logic behind your expected result. Else noone can help.array_merge_recursivecould work with one array. I've assumed incorrectly. I'm just trying to combine "APP" keys together and preserve the value assigned to the "TYPE" key.