This article mainly introduces two methods for removing duplicate items from two-dimensional arrays in php. you can compare them to see which one is more suitable for you, for more information about how to remove the duplicate values of two-dimensional arrays in php, see the following code:
Method 1:
// Remove the duplicate value from the two-dimensional array function array_unique_fb ($ array2D) {foreach ($ array2D as $ v) {$ v = join (',', $ v ); // reduce the dimension. you can also use implode to convert a one-dimensional array to a comma-connected string $ temp [] = $ v ;}$ temp = array_unique ($ temp ); // remove the duplicate string, that is, the repeated one-dimensional array foreach ($ temp as $ k => $ v) {$ temp [$ k] = explode (',', $ v); // re-assemble the split array} return $ temp ;}
Method 2:
// Remove duplicate values from the two-dimensional array and retain the key value function array_unique_fb ($ array2D) {foreach ($ array2D as $ k = >$ v) {$ v = join (', ', $ v); // dimension reduction. you can also use implode to convert a one-dimensional array to a comma-connected string $ temp [$ k] = $ v ;} $ temp = array_unique ($ temp); // remove the duplicate string, that is, the repeated one-dimensional array foreach ($ temp as $ k => $ v) {$ array = explode (',', $ v ); // re-assemble the split array // modify the following indexes as needed. $ temp2 [$ k] ['id'] = $ array [0]; $ temp2 [$ k] ['title'] = $ array [1]; $ temp2 [$ k] ['keyword'] = $ array [2]; $ temp2 [$ k] ['content'] = $ array [3];} return $ temp2 ;}
The two php methods to remove duplicate items of two-dimensional arrays have their own advantages and disadvantages. you can choose one based on your situation.