← All built-ins / array_slice()

array_slice()

array_slice(...$args): mixed

Parameters

NameTypeDescription
$aarrayinput array
$offsetintstart index (negative = from the end)
$lengthintmaximum 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

See also

array_splice()substr()