php截取数组段,array_slice—从数组中取出一段
php获取数组某个位置开始的值,只要用array_slice方法,将可以实现,还可以拿出位置的长度。可以用于对数组的值进行分页显示的时候处理,非常的高效简单。
array_slice() 例子
$input = array("a", "b", "c", "d", "e"); $output = array_slice($input, 2); // returns "c", "d", and "e" $output = array_slice($input, -2, 1); // returns "d" $output = array_slice($input, 0, 3); // returns "a", "b", and "c" // note the differences in the array keys print_r(array_slice($input, 2, -1)); print_r(array_slice($input, 2, -1, true));
输出:
Array ( [0] => c [1] => d ) Array ( [2] => c [3] => d )
本文作者: Liaodeity
本文链接: https://www.jianbaizhan.com/article/367
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!