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

标签 php arrays wordpress multidimensional-array

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

这是我的数组 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

)

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

最佳答案

array_unique(array_merge($array1,$array2), SORT_REGULAR);

http://se2.php.net/manual/en/function.array-unique.php

关于PHP - 将两个数组合并为一个数组(也删除重复项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13469803/

相关文章:

php - 查询失败 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册以获取正确的语法

php - 从数据库中获取所有月份的记录

python - 将形状 (n,) 的数组转换为形状 (n,1) 的 numpy 数组

php - 将 HTML 转换为 PHP Wordpress 页脚不起作用

javascript - prototype 和jQuery 和平共处?

php - Magento - 允许客户使用他们的 FedEx 帐户

php - 确定变量是否是 PHP 中一组变量中最小的

java - 如何在 Java 中合并两个排序的数组?

c++ - 动态内存分配并接受输入

html - 当我修改普通的 css 文件时,缩小的 CSS 文件不会更新 - Wordpress