开发者社区> 问答> 正文

PHP-将两个数组合并为一个数组(也删除重复项)

嗨,我正在尝试合并两个数组,并且还想从最终数组中删除重复的值。

这是我的数组1:

Array ( [0] => stdClass Object ( [ID] => 749 [post_author] => 1 [post_date] => 2012-11-20 06:26:07 [post_date_gmt] => 2012-11-20 06:26:07 ) 这是我的数组2:

Array ( [0] => stdClass Object ( [ID] => 749 [post_author] => 1 [post_date] => 2012-11-20 06:26:07 [post_date_gmt] => 2012-11-20 06:26:07

) 我array_merge用于将两个数组合并为一个数组。它正在给出这样的输出

Array ( [0] => stdClass Object ( [ID] => 749 [post_author] => 1 [post_date] => 2012-11-20 06:26:07 [post_date_gmt] => 2012-11-20 06:26:07

[1] => stdClass Object ( [ID] => 749 [post_author] => 1 [post_date] => 2012-11-20 06:26:07 [post_date_gmt] => 2012-11-20 06:26:07

) 我想删除这些重复的条目,或者在合并之前删除它们...请帮助。.谢谢!!!!

问题来源于stack overflow

展开
收起
保持可爱mmm 2020-02-08 11:11:29 700 0
1 条回答
写回答
取消 提交回答
  • array_unique(array_merge($array1,$array2), SORT_REGULAR);

    2020-02-08 11:11:38
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-直面PHP微服务架构挑战-高驰涛 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载