php array_slice函数的使用以及参数详解

 更新时间:2008年08月30日 19:59:51   作者:  
array array_slice ( array array, int offset [, int length]),根据 offset 和 length 参数所指定的 array 数组中的一段序列。offset 表示开始位置,length表示这段序列的长度.
复制代码 代码如下:

<?php
/*
用手册上的例子
*/
$input = array ("a", "b", "c", "d", "e");
$output = array_slice ($input, 2); // returns "c", "d", and "e",
$output = array_slice ($input, 2, -1); // returns "c", "d"
$output = array_slice ($input, -2, 1); // returns "d"
$output = array_slice ($input, 0, 3); // returns "a", "b", and "c"
?>

重点说下length 为负.它表示取数组一直到距离数组末端length这么远的距离

相关文章

最新评论