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_FlipKeysAndValues

Array_FlipKeysAndValues

Exchanges the keys and their associated values in the given array. The values must be numeric or string since they will now become keys.

Syntax

void Array_FlipKeysAndValues(
	Array array)

Parameters

Array array
Array to flip keys and values.

Examples

$array = Array("red", "green", "blue", 5) // This created the following array // 0 => "red" // 1 => "green" // 2 => "blue" // 3 => 5 Array_FlipKeysAndValues($array) // Now we have the following keys and values: // "red" => 0 // "green" => 1 // "blue" => 2 // 5 => 3 // If the values aren't string or numeric, // flipping keys and values will result in an error $array = Array(GetCurrentPage(), GetCurrentSection()) Array_FlipKeysAndValues($array) // Error: Cannot convert expression of type Object to an expression of type String // If the values aren't unique, latter values will write over former ones $array = Array(3, 5, 8, 5, 2, 3) // This created the following array // 0 => 3, 1 => 5, 2 => 8, 3 => 5, 4 => 2, 5 => 3 Array_FlipKeysAndValues($array) // Now we have the following keys and values: // 3 => 5, 5 => 3, 8 => 2, 2 => 4

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