我有两个数组像这样,在这种情况下,array_replace_recursive()不起作用,因为我编辑了相同内容以获得更多说明。
Array
(
[0] => stdClass Object
(
[Author] => 1
[totalComments] => 5
[commentsPoints] => 900
[commentDateDiffpoints] => 460
)
[1] => stdClass Object
(
[Author] => 2
[totalComments] => 4
[commentsPoints] => 720
[commentDateDiffpoints] => 24
)
[2] => stdClass Object
(
[Author] => 3
[totalComments] => 4
[commentsPoints] => 720
[commentDateDiffpoints] => 24
)
[3] => stdClass Object
(
[Author] => 18
[totalComments] => 4
[commentsPoints] => 720
[commentDateDiffpoints] => 24
)
)
和
Array
(
[0] => stdClass Object
(
[Author] => 1
[totalLikesGiven] => 5
[likesGivenOnTopicPoints] => 36
[likesGivenOnReplyPoints] => 108
[likesGivenOnBlogPoints] => 36
[DateDiffTopicpoints] => 1
[DateDiffReplypoints] => 3
[DateDiffBlogpoints] => 1
)
[1] => stdClass Object
(
[Author] => 3
[totalLikesGiven] => 1
[likesGivenOnTopicPoints] => 0
[likesGivenOnReplyPoints] => 0
[likesGivenOnBlogPoints] => 36
[DateDiffTopicpoints] => 0
[DateDiffReplypoints] => 0
[DateDiffBlogpoints] => 1
)
)
我喜欢这样的结果
Array
(
[0] => stdClass Object
(
[Author] => 1
[totalComments] => 5
[commentsPoints] => 900
[commentDateDiffpoints] => 460
[totalLikesGiven] => 5
[likesGivenOnTopicPoints] => 36
[likesGivenOnReplyPoints] => 108
[likesGivenOnBlogPoints] => 36
[DateDiffTopicpoints] => 1
[DateDiffReplypoints] => 3
[DateDiffBlogpoints] => 1
)
[1] => stdClass Object
(
[Author] => 2
[totalComments] => 4
[commentsPoints] => 720
[commentDateDiffpoints] => 24
)
[2] => stdClass Object
(
[Author] => 3
[totalComments] => 4
[commentsPoints] => 720
[commentDateDiffpoints] => 24
[totalLikesGiven] => 1
[likesGivenOnTopicPoints] => 0
[likesGivenOnReplyPoints] => 0
[likesGivenOnBlogPoints] => 36
[DateDiffTopicpoints] => 0
[DateDiffReplypoints] => 0
[DateDiffBlogpoints] => 1
)
[3] => stdClass Object
(
[Author] => 18
[totalComments] => 4
[commentsPoints] => 720
[commentDateDiffpoints] => 24
)
)
请帮助我如何在PHP中执行相同操作。
答案 0 :(得分:0)
$finalArr = array_replace_recursive($arr1,$arr2);
有类似的thread。在SO中有更多这样的问题。
答案 1 :(得分:-2)
使用数组合并php函数。 PHP array merge function