Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in Web Technology by (47.6k 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 (106k 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
asked Aug 6, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...