← All built-ins / array_splice()
array_splice()
array_splice(...$args): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $a | array | array (by reference) |
| $offset | int | start index |
| $length | int | how many elements to removeoptional |
| $replacement | array | elements inserted insteadoptional |
Return value
Array of the removed elements; the input array is modified.
Example
$a = [1, 2, 3, 4];
$gone = array_splice($a, 1, 2, ["x", "y"]);
echo implode(",", $gone), " / ", implode(",", $a);2,3 / 1,x,y,4