Onetastic Macro Documentation >
>
>
Array_Slice Array_Slice
Returns a new array containing a sequence of elements of the given array.
Syntax
Array Array_Slice(
Array array,
Numeric offset,
Numeric length,
Bool preserveKeys)
Parameters
- Array array
- Array to get elements from.
- Numeric offset
- The start offset to get 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, the resulting array can be shorter.
- Bool preserveKeys
- If true, the values in the resulting array will have the same keys as in the input array. If false, the resulting array will have numeric keys starting from zero.
Examples
$array = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
$slice = Array_Slice($array, 4, 3, false)
$slice = Array_Slice($array, 0, 4, false)
$slice = Array_Slice($array, -4, 2, false)
$slice = Array_Slice($array, -3, 3, false)
$slice = Array_Slice($array, 4, 3, true)
|