array_splice() removes the elements designated
length from the
input array, and replaces them with the
elements of the
replacement array, if
supplied. It returns an array containing the extracted elements.
Note that numeric keys in
input are not preserved.
offset is positive then the start of
removed portion is at that offset from the beginning of the
input array. If
offset is negative then it starts that far
from the end of the
length is omitted, removes everything
offset to the end of the array. If
length is specified and is positive, then
that many elements will be removed. If
length is specified and is negative then
the end of the removed portion will be that many elements from
the end of the array. Tip: to remove everything from
offset to the end of the array when
replacement is also specified, use
replacement array is specified, then
the removed elements are replaced with elements from this array.
length are such that nothing is removed,
then the elements from the
array are inserted in the place specified by the
offset. Note that keys in replacement
array are not preserved.
replacement is just one element it is
not necessary to put array()
around it, unless the element is an array itself.
The following statements change the values of
the same way:
Table 1. array_splice() equivalents
|array_push($input, $x, $y)||array_splice($input, count($input), 0, array($x, $y))|
|array_shift($input)||array_splice($input, 0, 1)|
|array_unshift($input, $x, $y)||array_splice($input, 0, 0, array($x, $y))|
|$input[$x] = $y // for arrays where key equals offset||array_splice($input, $x, 1, $y)|
Returns the array consisting of removed elements.
Example 1. array_splice() examples