Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macro Statements

Expression Editor

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Sorting objects

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: April 17, 2021
Also available as a single HTML file

Onetastic Macro Documentation > Functions > Array Functions > 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) // 3 elements starting at index 4 $slice = Array_Slice($array, 4, 3, false) // $slice is (5, 6, 7) // First 4 elements $slice = Array_Slice($array, 0, 4, false) // $slice is (1, 2, 3, 4) // 2 elements starting at 4th element from the end (7) $slice = Array_Slice($array, -4, 2, false) // $slice is (7, 8) // Last 3 elements $slice = Array_Slice($array, -3, 3, false) // $slice is (8, 9, 10) // Preserve keys $slice = Array_Slice($array, 4, 3, true) // $slice is: // 4 => 5 // 5 => 6 // 6 => 7

Reference

Statements

For

ForEach

If

Else If

Else

Switch

Case

Default

While

Expression

Comment

Break

Continue

Return

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Object Functions

String Functions