如何使用 Go 获取 slice 中的值?
How to get values in slice with Go?
对于 Go 中的一个切片,我想获取其中的所有项。
package main
import "fmt"
func main() {
var ids = []int{1, 2, 3}
fmt.Println(ids)
}
// [1 2 3]
如果使用这些 ID 在 MySQL 中搜索,喜欢
select * from posts where id IN (ids);
此处ids
应该是逗号分隔的数字,如
select * from posts where id IN (1,2,3);
有没有快速获取所有 id 值但不使用切片中的 for
循环的方法?
Is there a fast way to get all the id values but not use for loop from slice?
没有。您所能做的就是将循环隐藏在函数中。
对于 Go 中的一个切片,我想获取其中的所有项。
package main
import "fmt"
func main() {
var ids = []int{1, 2, 3}
fmt.Println(ids)
}
// [1 2 3]
如果使用这些 ID 在 MySQL 中搜索,喜欢
select * from posts where id IN (ids);
此处ids
应该是逗号分隔的数字,如
select * from posts where id IN (1,2,3);
有没有快速获取所有 id 值但不使用切片中的 for
循环的方法?
Is there a fast way to get all the id values but not use for loop from slice?
没有。您所能做的就是将循环隐藏在函数中。