合并两个数组在PHP从一个选择查询:更新


Merge Two Array in PHP got from a select query : UPDATE

我有两个这样的数组,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做同样的

使用array_replace_recursive:

$finalArr = array_replace_recursive($arr1,$arr2);

有一个类似的线程。还有更多类似的问题,请参见

使用数组合并php函数。PHP数组合并函数