Array_splice
(PHP 4 and PHP 5)
Array_splice-some arrays are deleted and replaced with others
Description
Array array_splice (array & $ investment, international $ offset [Abstract $ Length = 0 [, mixed $ change])
Delete the specified element offset and length input array, and replace their content to replace the array if provided.
Note that the input number key is not saved.
Note: If the replacement is not an array, it will be a stereotype (that is, the (array) $ parameter ). This may cause unexpected behavior when an object is replaced.
Parameters
Input
Input array.
Offset
If offset is positive then partial offset is removed from the first input array. If offset is negative and then it starts, the input array is far from the bottom.
Length
If the length is omitted, delete all arrays from the end of the offset. If the specified length is positive, many contents will be deleted. If the specified length is negative, the ending part is deleted, and the ending array of many elements is deleted. Tip: remove all replacement arrays from the end of the offset and also specify that the length of the count ($ input) is used.
Change
If you replace the specified array, then the content to be deleted is changed to the array from which the molecules are removed.
If the offset and length are not deleted, the element replaces the specified location offset inserted in the array. Note that the replacement key array is not saved.
If you just replace an element, there is no need to enclose the array () unless the element is an array itself.
Return value
Returns the extracted content composed of arrays.
Instance
Example #1 array_splice ()
<? Php
$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 2 );
// $ Input is now array ("red", "green ")
$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 1,-1 );
// $ Input is now array ("red", "yellow ")
$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 1, count ($ input), "orange ");
// $ Input is now array ("red", "orange ")
$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input,-1, 1, array ("black", "maroon "));
// $ Input is now array ("red", "green ",
// "Blue", "black", "maroon ")
$ Input = array ("red", "green", "blue", "yellow ");
Array_splice ($ input, 3, 0, "purple ");
// $ Input is now array ("red", "green ",
// "Blue", "purple", "yellow ");
?>