且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用php将数组拆分为两个相等的部分

更新时间:2022-04-25 21:39:27

来自 array_slice的文档,您要做的就是给array_slice一个偏移量和一个长度.

From the documentation for array_slice, all you have to do is give array_slice an offset and a length.

在您的情况下:

$firsthalf = array_slice($original, 0, 1200);
$secondhalf = array_slice($original, 1200);

换句话说,这段代码告诉array_slice:

In other words, this code is telling array_slice:

take the first 1200 records;
then, take all the records starting at index 1200;

由于索引1200是项目1201,因此这应该是您所需要的.

Since index 1200 is item 1201, this should be what you need.