PHPize Online / SQLize Online
A A A

Donate Popular

array_splice

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

array_splice — Remove a portion of the array and replace it with something else.

Description

array_splice(
    array &$array,
int $offset,
?int $length = null,
mixed $replacement = []
): array
Removes the elements designated by offset and length from the array array, and replaces them with the elements of the replacement array, if supplied.

Parameters

array
The array to work on.
offset
The offset to start removing elements from.
length
The number of elements to remove. If not supplied, removes all elements from offset to the end of the array.
replacement
The elements to replace the removed elements with. If not supplied, replaces the removed elements with null.

Return Values

Returns an array consisting of the extracted elements.