[英]Split Multi-dimensional Array Into Multiple Arrays
I have an array: 我有一个数组:
Array
(
[0] => Array
(
[u_id] => 2
[u_name] => Test USER
[r_nb_today] => 2
[r_nb_total] => 4
)
[1] => Array
(
[u_id] => 4
[u_name] => Test USER
[r_nb_today] => 0
[r_nb_total] => 0
)
[2] => Array
(
[u_id] => 5
[u_name] => Test USER
[r_nb_today] => 0
[r_nb_total] => 0
)
[3] => Array
(
[u_id] => 6
[u_name] => Test USER
[r_nb_today] => 0
[r_nb_total] => 0
)
)
The array is bigger than this, Now I want to keep it as is with the same order and split it into multiple arrays with a limit of 10 entries each (like LIMIT 10 in SQL). 数组大于此数组。现在,我想按相同顺序将其保留,并将其拆分为多个数组,每个数组最多限制10个条目(例如SQL中的LIMIT 10)。
How to do that? 怎么做?
Thanks. 谢谢。
As per @devpro comment (write it here to have official answer): 按照@devpro的注释(在此处写下以得到官方答复):
You can use array-chunk which chunks an array into arrays with size elements. 您可以使用array-chunk ,将一个数组分成具有size元素的数组。 The last chunk may contain less than size elements.
最后一块可能包含少于size的元素。
Use it in your case as: 在您的情况下使用它:
$chuncks = array_chunk($array, $limit));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.