PHP » GoLang |
login |
register |
about
|
array_chunkarray_chunk[code] func ArrayChunk(s []interface{}, size int) [][]interface{} { if size < 1 { panic("size: cannot be less than 1") } length := len(s) chunks := int(math.Ceil(float64(length) / float64(size))) var n [][]interface{} for i, end := 0, 0; chunks > 0; chunks-- { end = (i + 1) * size if end > length { end = length } n = append(n, s[i*size:end]) i ++ } return n } [/code] |