Home » » array_slice

array_slice

Written By 1 on Tuesday, October 2, 2012 | 9:13 AM

array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = false ]] )

Extract a slice of the array

array_slice() returns the sequence of elements from the array array as specified by the offset and length parameters.


<?php
$input 
= array("a""b""c""d""e");

$output array_slice($input2);      // returns "c", "d", and "e"
$output array_slice($input, -21);  // returns "d"
$output array_slice($input03);   // returns "a", "b", and "c"

// note the differences in the array keys
print_r(array_slice($input2, -1));
print_r(array_slice($input2, -1true));
?>

5.0.2 The optional preserve_keys parameter was added.


0 Comment:

Post a Comment