← All built-ins / array_splice()

array_splice()

array_splice(...$args): mixed

Parameters

NameTypeDescription
$aarrayarray (by reference)
$offsetintstart index
$lengthinthow many elements to removeoptional
$replacementarrayelements 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

See also

array_slice()unset()