【发布时间】:2019-05-30 05:23:56
【问题描述】:
我一直想知道如何将 2 个多维数组加在一起,我找到了类似的解决方案,但这并不是我想要的。也许你们中的一个可以帮助我。是的,我知道标题与其他问题几乎相同,但请相信我,我一直在寻找答案,但找不到。
# 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
)
)
如您所见,我想将 2 个数组加在一起。我已经看到了其他几个答案,但他们使用内置 php 函数array_merge()。如果我使用它,它会导致这样的结果:
#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
)
)
)
如您所见,不幸的是,这不是我想要的。我希望为我的问题找到解决方案。
感谢您阅读我的帖子。
干杯科迪
【问题讨论】:
-
写你的owm函数,很简单。