Golang对元素slice并去重
参考博客:
https://blog.csdn.net/qq_27068845/article/details/77407358
封装的类似PHP的array_column
// ArrayColumn 获取二维数组某一个键值 func ArrayColumn(input []map[string]interface{},columnKey string) ([]interface{}){ if len(input)==0 { return []interface{}{} } result := []interface{}{} // for i := 0; i < len(input); i++ { // result = append(result, input[i][columnKey]) // } for _,v := range input { fmt.Print(v[columnKey]) result = append(result, v[columnKey]) } return result } // ArrayUnique 数组去重 func ArrayUnique(input []string)([]string){ result := []string{} // 存放不重复主键 tempMap := map[string]byte{} for _, e := range input{ l := len(tempMap) tempMap[e] = 0 if len(tempMap) != l{ // 加入map后,map长度变化,则元素不重复 result = append(result, e) } } return result }
相关推荐
Lzs 2020-10-23
Justhavefun 2020-10-22
周游列国之仕子 2020-09-15
风雨断肠人 2020-09-04
聚合室 2020-11-16
零 2020-09-18
jacktangj 2020-10-14
ChaITSimpleLove 2020-10-06
Andrea0 2020-09-18
afanti 2020-09-16
88234852 2020-09-15
YClimb 2020-09-15
卖口粥湛蓝的天空 2020-09-15
stulen 2020-09-15
pythonxuexi 2020-09-06
abfdada 2020-08-26
梦的天空 2020-08-25