+1 vote
1 view
in Web Technology by (42.8k 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 (96.4k points)
edited by

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

Want to learn Angularjs from basics! Here's the right video for you on  Angularjs provided by Intellipaat:

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...