A one-dimensional array can be array_unique directly using the () function, or use two times array_flip () to go heavy, but the multidimensional array will need to write its own
The previous few days a simple Deduplication method was written for several fields in a two-dimensional array that require special inability to duplicate
Private functionUnique_arr ($data) { $temp=Array(); foreach($data as $key=$datum) { $k=$datum[' site ']. ", {$datum[' No ']},{$datum[' Code ']},{$datum[' Type ']} ";//Dimensionality , will need to join the unique field stitching into a string to make the keys of the array $temp[$k] =$datum; } $temp _final= []; foreach($temp as $v){ $temp _final[] =$v;//re-assemble the disassembled array } return $temp _final; }
This is because the specified fields need to be federated unique, so when the same time occurs, because of the nature of the array, when the key name already exists, the key value will be replaced by the last value corresponding to this key name, so when there is duplicate content, will replace the previous data, only the last one to retain the data, Thus achieving a de-weight effect
PHP Array de-weight