且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP - 合并两个阵列成一个阵列(也删除重复)

更新时间:2023-11-23 16:27:10

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

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