Arrays
...
Arrays
An Array is an object that contains an ordered list of other objects. For example the following creates an Array of 7 items and assigns it into the $-Variable $weekDays:
$weekDays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
...
The majority of Arrays that you are likely to use will contain values of one type e.g. all Numbers however Arrays can contain values of different types:
...
Note that $oddArray[5] is itself an Array! This can be useful in some very complex processing logic.
Getting / Setting the value of an Array Element
To use the nth item in the Array, use either the syntax array[n] or getElement(array,n) or array.n :
Expression | Result |
---|---|
$day = $weekDays[3] | Sets $day to "Wednesday" |
$i = 3, $day = $weekDays[$i+2] | Sets $day to "Friday" |
$day = getElement($weekDays,4) | Sets $day to "Thursday" |
$day = $weekDays.3 | Sets $day to "Wednesday" |
$day = $weekDays[9] | Sets $day to _NULL since there is no element at position 9 |
$weekDays = _NULL, $day = $weekDays.3 | Sets $day to _NULL since there is no element at position 3 (in fact there are no elements at all) |
$weekDays = [], $day = getElement($weekDays,3) | Sets $day to _NULL since there is no element at position 3 (in fact there are no elements at all) |
Similarly, to set the value of the nth item in an Array, use setElement(array,n,value):
...
However setElement($months,13,"Lunar") would cause PhixFlow to generate an error and stop processing as the expression is trying to update an item that do not exist.
Array Operations
See Array Handling for a full list functions that can be used with Arrays. However the most frequently used functions are:
Function | Description |
---|---|
getElement() | Get the value of a specific element within an Array |
addElement() | Add a new element to the end of an Array |
countElements() | Get the number of elements within an Array |
listContains() | Provides the position of a value within an Array |
split() | Turn a String of delimited values (e.g. a comma-separated list) into an Array |
Records Sets
A Record Set is an object containing one or more rows of data (usually returned from a Pipe). Entries within Record Sets can be referred to using the name of the Attribute value. In the examples below:
...
Expression | Result |
---|---|
$accountNum = account.accountNum | account.accountNum returns the value of the Attribute accountNum within the Record Set account. Because the Pipe just returns a single value, $accountNum is a single value (not an Array). |
$invoiceNumbers = invoices.number | invoices.number returns an Array of the Attribute number within the Record Set invoices. |
$firstInvoiceNumber = invoices.number[1] | This gets the first invoice number. |
$firstInvoice = invoices[1], $firstInvoiceNumber = $firstInvoice.number | This also gets the first invoice number. Note that the Record Set invoices[1] has been assigned into a $-Variable. |
$attr = "number", $invoiceNumbers = invoices.$attr | This also creates an Array of the invoice numbers. Note that the $-Variable $attr has been set to the name of the Attribute which is then used to decide which Attribute to read from invoices. |
Syntax pipe.attribute1:attribute2
Sometimes it is useful to construct a new Record Set containing a subset of the Attributes on the original Pipe. This can be done using the syntax:
...