赞
踩
golang实现php的array_chunk函数
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 }
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
– 将一个数组分割成多个
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。