The declaration of an "array of arrays" is an alternative syntax for multidimensional arrays. A collection of elements is nested instead of dimensioning the elements. The nesting depth is unlimited.
Syntax for declaration
<variable name> : ARRAY[ <any dimension> ] OF ARRAY[ <any dimension> ] OF <data type> := <initialization> ;
Syntax for data access
<variable name> [<index of first array> ] [<index of next array> ]
|
Name of the array Example: |
|
Nested array in three levels Example: NOTE: The nesting depth is unlimited. |
|
Data type of an element:
|
|
Optional Initial values for the nested array |
Example
PROGRAM PLC_PRG VAR aiPoints : ARRAY[1..2,1..3] OF INT := [1,2,3,4,5,6]; ai2Boxes : ARRAY[1..2] OF ARRAY[1..3] OF INT := [ [1, 2, 3], [ 4, 5, 6]]; ai3Boxes : ARRAY[1..2] OF ARRAY[1..3] OF ARRAY[1..4] OF INT := [ [ [1, 2, 3, 4], [5, 6, 7, 8 ], [9, 10, 11, 12] ], [ [13, 14, 15, 16], [ 17, 18, 19, 20], [21, 22, 23, 24] ] ]; ai4Boxes : ARRAY[1..2] OF ARRAY[1..3] OF ARRAY[1..4] OF ARRAY[1..5] OF INT; END_VAR aiPoints[1, 2] := 1200; ai2Boxes[1][2] := 1200;
The variables aiPoints
and ai2Boxes
collect the same data elements, however the syntax for the declaration differs from
that of the data access.

