Data type: Array

The array data type is a compound data type represented by the number 8 in the database dictionary. Arrays store a list of elements of the same data type accessed by an index (element) number. The term array is synonymous with the terms list, vector, and sequence. Elements in arrays can be of any data types (including arrays or structures). A fully qualified array name (array field in $file) can be used in place of an array variable. The number of items in an array can vary and does not have to be allocated in advance. Arrays are delimited by curly braces ({ }). The following table shows some examples.

Description Literal examples
Numeric {1,2,3}
Character {"a","b","c","f","e","h"}
Boolean {true, true, unknown}
Time {'12/7/42 00:00', '1/3/62 00:00'}
Nested {{1,2},{3,4}}
Structures {{[1,"a"]},{[2,"b"]}}
{{[1,"a",true]},{[2,"b",false]},{[3,"c",unknown]}}
Empty {}

You can use either of the following equivalent syntaxes to access an element in an array:

  • $array[element_number]
  • element_number in $array

For example, to extract the value of the first customer number (2753) in the array $customer with value {2753, 2842, 2963}, use any of the following equivalent syntaxes:

  • 1 in $customer
  • $customer[1]

If the accessed array element does not exist, the element is created and set to NULL. This effectively extends the array. To insert a value into an array use the insert RAD function. To delete an element from an array, use the delete RAD function.

Tip You can use the denull RAD function to remove any null values from the end of an array before assigning the array to a record or adding it to the database.