如何在 PHP 中使用 array_slice() 将数组分成两个相等的部分?
这是我的要求:
第一个数组包含:0-1200
第二个数组包含:1200-end
From array_slice 的文档 https://www.php.net/array_slice,你所要做的就是给予array_slice
偏移量和长度。
在你的情况下:
$firsthalf = array_slice($original, 0, 1200);
$secondhalf = array_slice($original, 1200);
换句话说,这段代码告诉我们array_slice
:
take the first 1200 records;
then, take all the records starting at index 1200;
由于索引 1200 是项目 1201,因此这应该是您所需要的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)