Golang查找字符是否在数组中,例如:php中的in_arra
作者:
彩色代码 | 来源:发表于
2020-07-21 13:52 被阅读0次//查找字符是否在数组中
func InArray(obj interface{}, target interface{}) (bool) {
targetValue := reflect.ValueOf(target)
switch reflect.TypeOf(target).Kind() {
case reflect.Slice, reflect.Array:
for i := 0; i < targetValue.Len(); i++ {
if targetValue.Index(i).Interface() == obj {
return true
}
}
case reflect.Map:
if targetValue.MapIndex(reflect.ValueOf(obj)).IsValid() {
return true
}
}
return false
}
本文标题:Golang查找字符是否在数组中,例如:php中的in_arra
本文链接:https://www.haomeiwen.com/subject/hysikktx.html
网友评论