I have been wondering how to add 2 multidimensional arrays together, I have found similar solutions but it is not exactly what I am trying to go for. Maybe one of you guys could help me out. Yes I know the title is almost the same as other asked questions, but trust me, I have looked for my answer but I can't find it.
# array1
Array
(
[0] => Array
(
[0] => Product1
[1] => Description product 1
)
[1] => Array
(
[0] => Product2
[1] => Description product 2
)
[2] => Array
(
[0] => Product3
[1] => Description product 3
)
)
# array2
Array
(
[0] => Array
(
[0] => Price 1
[1] => Something product 1
)
[1] => Array
(
[0] => Price 2
[1] => Something product 2
)
[2] => Array
(
[0] => Price 3
[1] => Something product 3
)
)
#resultant array
Array
(
[0] => Array
(
[0] => Product1
[1] => Description product 1
[3] => Price 1
[4] => Something product 1
)
[1] => Array
(
[0] => Product2
[1] => Description product 2
[2] => Price 2
[3] => Something product 2
)
[2] => Array
(
[0] => Product3
[1] => Description product 3
[2] => Price 3
[3] => Something product 3
)
)
As you can see I would like to add the 2 arrays together. I have seen several other answers but they use the build in php function array_merge()
. If I use that it will result in something like this:
#resultant array
Array
(
[0] => Array
(
[0] => Product1
[1] => Description product 1
)
[1] => Array
(
[0] => Product2
[1] => Description product 2
)
[2] => Array
(
[0] => Product3
[1] => Description product 3
)
[3] => Array
(
[0] => Price 1
[1] => Something product 1
)
[4] => Array
(
[0] => Price 2
[1] => Something product 2
)
[5] => Array
(
[0] => Price 3
[1] => Something product 3
)
)
)
As you can see that is not what I am looking for unfortunately. I am hoping to find a solution for my problem.
Thanks for reading my post.
Cheers Cody