-
-
//Function 1, two-dimensional array to remove duplicate values - function array_unique_fb($array2D){
- foreach ($array2D as $v){
- $v = join( ",",$v); //For dimensionality reduction, you can also use implode to convert a one-dimensional array into a string connected with commas
- $temp[] = $v;
- }
- $temp = array_unique($temp) ; //Remove repeated strings, that is, repeated one-dimensional arrays
- foreach ($temp as $k => $v){
- $temp[$k] = explode(",",$v); / /Reassemble the disassembled array
- }
- return $temp;
- }
//Function 2, two-dimensional array removes duplicate values and retains key values
- function array_unique_fb($array2D) {
- foreach ($array2D as $k=>$v){
- $v = join(",",$v); //For dimensionality reduction, you can also use implode to convert one-dimensional arrays into comma-connected ones String
- $temp[$k] = $v;
- }
- $temp = array_unique($temp); //Remove repeated strings, that is, repeated one-dimensional arrays
- foreach ($temp as $k => ; $v){
- $array=explode(",",$v); //Reassemble the disassembled 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;
- }
- ?>
-
Copy code
Call example:
-
- $arr = array("a"=>array("a"=>"welcome","b"=>"to","c"=> "bbs.it-home.org"),
- "b"=>array("a"=>"Programmer's Home","b"=>"jbxue.com","c"=> ;"beijing")
- );
- $arr2 = array_unique_fb($arr)
- ?>
Copy code
Articles you may be interested in:
Two examples of removing duplicate data from arrays in php
Example analysis of PHP two-dimensional array deduplication
PHP array deduplication function code example
A simple example of php array deduplication (one-dimensional and two-dimensional array deduplication)
PHP array deduplication method reference (one-dimensional array deduplication, two-dimensional array deduplication)
How to determine and remove duplicate data in an array using php
Implementation code for removing repeated combinations in a two-dimensional array
php custom function to remove duplicates from two-dimensional array
php array_unique example of removing duplicate values from a one-dimensional array
Small example of php array deduplication
|