Onetastic Macro Documentation >
>
>
Array_Splice Array_Splice
Removes a a sequence of elements of the given array and replaces it with the given array. Numeric keys in the input array is not preseved and re-numbered from 0.
Syntax
void Array_Splice(
byref Array array,
Numeric offset,
Numeric length,
Array replacement)
Parameters
- Array array
- Array to remove and replace elements from.
- Numeric offset
- The start offset to remove and replace elements. If non-negative, the sequence will start that far away from the beginning of the array. If negative, the sequence will start that far away from the end of the array.
- Numeric length
- The length of the sequence. If there aren't that many elements in the array, all the elements till the end of the array will be removed and replaced. If given as zero, no elements will be removed but the new elements will be inserted at given offset.
- Array replacement
- The set of elements to replace with. If this is an empty array, elements are removed only. Keys in the replacement array is ignored.
Examples
$array = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Array_Splice($array, 4, 3, Array(97, 98))
Array_Splice($array, 0, 4, Array())
Array_Splice($array, -4, 2, Array(0, -1, -2))
Array_Splice($array, -3, 3, Array(0))
Array_Splice($array, 0, 0, Array(3, 4, 5))
Array_Splice($array, Array_Length($array), 0, Array(7, 8, 9))
|