A php function that removes repeated items in a two-dimensional array
// Function 1. remove duplicate values from two-dimensional arrays
- Function array_unique_fb ($ array2D ){
- Foreach ($ array2D as $ v ){
- $ V = join (",", $ v); // dimension reduction. you can also use implode to convert a one-dimensional array to a string connected with commas (,).
- $ Temp [] = $ v;
- }
- $ Temp = array_unique ($ temp); // remove the duplicate string, that is, the duplicate one-dimensional array.
- Foreach ($ temp as $ k => $ v ){
- $ Temp [$ k] = explode (",", $ v); // re-assemble the split array
- }
- Return $ temp;
- }
// Function 2. remove duplicate values from two-dimensional arrays and retain key values.
- 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 string connected with commas (,).
- $ Temp [$ k] = $ v;
- }
- $ Temp = array_unique ($ temp); // remove the duplicate string, that is, the duplicate one-dimensional array.
- Foreach ($ temp as $ k => $ v ){
- $ Array = explode (",", $ v); // re-assemble the split array
- $ Temp2 [$ k] ["id"] = $ array [0];
- $ Temp2 [$ k] ["litpic"] = $ array [1];
- $ Temp2 [$ k] ["title"] = $ array [2];
- $ Temp2 [$ k] ["address"] = $ array [3];
- $ Temp2 [$ k] ["starttime"] = $ array [4];
- $ Temp2 [$ k] ["endtime"] = $ array [5];
- $ Temp2 [$ k] ["classid"] = $ array [6];
- $ Temp2 [$ k] ["ename"] = $ array [7];
- }
- Return $ temp2;
- }
- ?>
Call example:
- $ Arr = array ("a" => array ("a" => "welcome", "B" => "to", "c" => "bbs.it-home.org "),
- "B" => array ("a" => "Programmer's House", "B" => "jbxue.com", "c" => "beijing ")
- );
- $ Arr2 = array_unique_fb ($ arr)
- ?>
Articles you may be interested in: php two examples of removing duplicate data from arrays PHP two-dimensional array de-duplicated instance parsing php array de-duplicated function code example php array de-duplicated (one-dimensional, two-dimensional array de-duplicated) php array deduplication method reference (one-dimensional array deduplication, two-dimensional array deduplication) php method for judging and removing repeated data from arrays removing repeated combinations in two-dimensional arrays implementation code php two-dimensional array de-duplication user-defined function php array_unique one-dimensional array removal example php array de-duplication example of duplicate values |