+1 vote
1 view
in Web Technology by (19.9k points)

Hi, I'm trying to merge two arrays and also want to remove duplicate values from the final Array.

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

)

And 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 these duplicate entries or can I remove these before merging... Please help.. Thanks!!!!!!!

1 Answer

0 votes
by (50k points)

You can use the following piece of code for Merging two arrays into one array

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

...