...
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"]
There are several ways in which Arrays are created within PhixFlow:
- The simplest case is shown above i.e. the Array is created explicitly using the [value1, value2,..] syntax.
- An Array of Integers between the values n and m can be created using the expression [n..m] e.g. [51..100] creates an Array of 50 elements [51, 52, ... 100].
- Arrays can also be created by Array Handling Functions functions e.g. split() which turns a String into an Array.
- Finally an Array can be generated by referring to an Attribute on a Pipe when that Pipe contains several rows. In this case the Array has an entry for each row in the Pipe and the value of each entry is value of the specified Attribute. For example:
Expression | Result |
---|---|
| invoice is the name of a pipe which looks up all invoices for a customer (in fact it produces a Record Set which is discussed below. invoice.value creates an Array of all the value Attributes in invoice. E.g. if the customer had 3 invoices of value 100, 150 and 125, then invoice.value would be the Array [100, 150, 125]. countElements(), max() and average() show examples of the arrays being used. Note that $average1 and $average2 will contain the same result. |
...
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" |
| 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 |
| Sets $day to _NULL since there is no element at position 3 (in fact there are no elements at all) |
| 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):
Expression | Result |
---|---|
setElement($months,3,"March") | Sets the 3rd element of the Array $months to "March" |
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.
...
- account is a Pipe which contain a single record of account details.
- invoices is a Pipe which contains several invoice records for that account.
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. |
| This also gets the first invoice number. Note that the Record Set invoices[1] has been assigned into a $-Variable. |
| 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. |
...
This form is useful when comparing selected Attributes on one Pipe with selected Attributes on another Pipe. For example:
Expression | Result |
---|---|
eq(newAccount.accountNum:customerId:custName, oldAccount.accNumber:custId:customerName) | This returns true if the Pipes newAccount and oldAccount contain matching details for the referenced Attributes. |
...