PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

array_slice

Tags: PHP 5.x PHP 7.x PHP 8.x

array_slice — Extract a slice of the array.

Description

array_slice(
    array $array,
int $offset,
?int $length = null,
bool $preserve_keys = false
): array
array_slice() returns the sequence of elements from the array array as specified by the offset and length parameters.

Parameters

array
The input array.
offset
The offset to start from.
length
The length of the slice.
preserve_keys
Whether or not to preserve keys.

Return Values

Returns the slice. If the offset is larger than the size of the array, an empty array is returned.

array_slice - New snippets