PHP array RemovalRepeated itemsThere is a built-in FunctionArray_unique(), But the array_unique function of PHP is only applicable to one-dimensional arrays and does not apply to multi-dimensional arrays. The following providesTwo-dimensional arrayArray_unique Function
// Remove duplicate values from two-dimensional arrays
Function Array_unique_fb ( $ Array2d ) {
Foreach ( $ Array2d As $ V ) {
$ V = Join ( "," , $ V ) ; // Dimensionality 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 ;
}
// 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 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;
}