To merge the duplicate value in a multidimensional array in PHP, first, create an empty array that will contain the final result. Then we iterate through each element in the array and check for its duplicity by comparing it with other elements. If duplicity is found then first merge the duplicate elements and then push it to the final array else directly push to the final array.
Below example illustarte the above approach in a more significant way:
Example 1: In this example the duplicity is not more than two.
Array (  => Array (  => Array ( [Roll] => 43 [name] => Geeeks [subject] => Course-011 )  => Array ( [Rool] => 43 [name] => Geeks [subject] => Course-011 ) )  => Array ( [Rool] => 38 [name] => Gfg [subject] => Course-012 ) )
Example 2: In this example the duplicate field is more than two.
Array ( [Course-011] => Array (  => Array ( [Roll] => 43 [name] => Geeks [subject] => Course-011 )  => Array ( [Roll] => 38 [name] => GFG [subject] => Course-011 )  => Array ( [Roll] => 26 [name] => GeeksforGeeks [subject] => Course-011 ) ) [Course-012] => Array (  => Array ( [Roll] => 31 [name] => gfg [subject] => Course-012 ) ) )
- Multidimensional Array in R
- Multidimensional Associative Array in PHP
- PHP multidimensional array search by value
- How to search by key=>value in a multidimensional array in PHP ?
- How to check an array is multidimensional or not in PHP ?
- Convert multidimensional array to XML file in PHP
- Sort a multidimensional array by date element in PHP
- PHP | Remove duplicate elements from Array
- Golang Program that Removes Duplicate Elements From the Array
- Multidimensional arrays in PHP
- Perl | Multidimensional Hashes
- Perl | Multidimensional Arrays
- Multidimensional Arrays in Java
- How to merge the first index of an array with the first index of second array?
- How to Remove Duplicate Values from Slice in Golang?
- How to merge two PHP objects?
- D3.js | d3.merge() function
- Merge Strategies in Git
- Git-Checkout And Merge
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.