Php 3D array deduplication (sample code ). Suppose it is called array $ my_array; copy the code as follows: create an empty array. $ tmp_arrayarray (); $ new_arrayarray (); 1. loop all rows. ($ val is a row) suppose it is an array $ my_array;
The code is as follows:
// Create an empty array.
$ Tmp_array = array ();
$ New_array = array ();
// 1. loop all rows. ($ val is a row)
Foreach ($ my_array as $ k => $ val ){
$ Hash = md5 (json_encode ($ val ));
If (in_array ($ hash, $ tmp_array )){
Echo ('the line already exists ');
} Else {
// 2. in The foreach loop body, assign the hash values of each array object to the temporary array.
$ Tmp_array [] = $ hash;
$ New_array [] = $ val;
}
}
Print_r ($ new_array );
$ New_array is an array with no duplicate data after filtering.
Else $ my_array; code: // create an empty array. $ tmp_array = array (); $ new_array = array (); // 1. loop all rows. ($ val is a row )...