← All built-ins / array_slice()
array_slice()
array_slice(...$args): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $a | array | input array |
| $offset | int | start index (negative = from the end) |
| $length | int | maximum element countoptional |
Return value
The extracted section as a new array.
Example
$s = array_slice([1, 2, 3, 4, 5], 1, 3);
echo implode(",", $s), "
";
echo implode(",", array_slice([1, 2, 3, 4], -2)), "
";2,3,4 3,4