array_slice

(PHP 4 )

array_slice -- 配列を要素を展開する

説明

array array_slice ( array array, int offset [, int length])

array_slice() は、 array からパラメータ offset および length で指定された連続する要素を返します。

offset が正の場合、要素位置の計算は、 配列 array のoffsetから始められます。 offset が負の場合、要素位置の計算は array の最後から行われます。

length が指定され、正の場合、 連続する複数の要素が返されます。 length が 指定され、負の場合、配列の末尾から連続する複数の要素が返されます。 省略された場合、 offset から配列の最後まで の全ての要素が返されます。

例 1 array_slice() の例

$input = array ("a", "b", "c", "d", "e");

$output = array_slice ($input, 2);      // "c", "d", "e"を返します
$output = array_slice ($input, 2, -1);  // "c", "d"を返します
$output = array_slice ($input, -2, 1);  // "d"を返します
$output = array_slice ($input, 0, 3);   // "a", "b", "c"を返します


array_splice() も参照下さい。