PHP-将两个数组合并为一个数组(也删除重复项) [英] PHP - Merging two arrays into one array (also Remove Duplicates)

查看:80
本文介绍了PHP-将两个数组合并为一个数组(也删除重复项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I'm Trying to merge two arrays and also want to remove duplicate values from final 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将两个数组合并为一个数组.它正在给出这样的输出

I'm using array_merge for merging both arrays into one array. it is giving output like this

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

)

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

I want to remove these duplicate entries or can I remove these before merging... Pleas help.. Thanks!!!!!!!

推荐答案

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

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

这篇关于PHP-将两个数组合并为一个数组(也删除重复项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆