PHP - 合并两个阵列成一个阵列(也删除重复) [英] PHP - Merging two array into one array (also Remove Duplicates)

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

问题描述

嗨我试图合并两个阵列还希望从最终的阵列中删除重复值。

下面是我的数组
1:

 阵列
    (
    [0] => stdClass的对象
    (
    [ID] => 749
    [post_author] => 1
    [POST_DATE] =>二○一二年十一月二十○日6时26分07秒
    [post_date_gmt] =>二○一二年十一月二十○日6时26分07秒

这是我的数组2:

 阵列

[0] => stdClass的对象

[ID] => 749
[post_author] => 1
[POST_DATE] =>二○一二年十一月二十○日6时26分07秒
[post_date_gmt] =>二○一二年十一月二十○日6时26分07秒)

我用 array_merge 合并两个数组到一个数组。它给这样的输出

 阵列

[0] => stdClass的对象

[ID] => 749
[post_author] => 1
[POST_DATE] =>二○一二年十一月二十○日6时26分07秒
[post_date_gmt] =>二○一二年十一月二十○日6时26分07秒[1] => stdClass的对象

[ID] => 749
[post_author] => 1
[POST_DATE] =>二○一二年十一月二十○日6时26分07秒
[post_date_gmt] =>二○一二年十一月二十○日6时26分07秒)

我想删除这个重复的条目或我可以合并之前将其删除...
普莱斯帮助..
谢谢!!!!!!!


解决方案

  array_unique(array_merge($数组1,$数组2),SORT_REGULAR);

<一个href=\"http://se2.php.net/manual/en/function.array-unique.php\">http://se2.php.net/manual/en/function.array-unique.php

Hi I'm Trying to merge two arrays also want to remove duplicate values from final Array.

Here is my Arrays 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
)

This is my array 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

)

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 this duplicate entry or can I remove it 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天全站免登陆