I'm trying to assign two initialized arrays evenNumbers and oddNumbers to an array of arrays integers:
PROGRAM ArrayInit
VAR
evenNumbers : ARRAY[1..3] OF INT := [2, 4, 6];
oddNumbers: ARRAY[1..3] OF INT := [1, 3, 5];
integers : ARRAY[1..2] OF ARRAY[1..3] OF INT := [evenNumbers, oddNumbers];
END_VAR
This code gives me a compiler error
Array initialisation expected
Of course I can directly initialize integers with the numbers that I want like so:
PROGRAM ArrayInit
VAR
integers: ARRAY[1..2] OF ARRAY[1..3] OF INT := [
[2, 4, 6], [1, 3, 5]
];
END_VAR
or like Sergey mentioned
PROGRAM ArrayInit
VAR
integers: ARRAY[1..2, 1..3] OF INT := [
2, 4, 6, 1, 3, 5
];
END_VAR
However, if the original arrays are very big and/or I want to document what these different arrays are, a descriptive name would be nice. I.e. integers : ARRAY[1..2] OF ARRAY[1..3] OF INT := [evenNumbers, oddNumbers]; nicely shows that the integers has two lists, one with even and one with odd numbers.
I've also tried to initialize integers as integers: ARRAY[1..2] OF ARRAY[1..3] OF INT := [[evenNumbers], [oddNumbers]];, but this gives me the compiler error:
Cannot convert type 'ARRAY [1..3] OF INT' to type 'INT'
Now I wonder if it even possible? If so, does anyone know how I can do it?



To assign multiple level array you do it in one line.
will result in array
SO first it assign all element of first element
[1, 1],[1, 2],[1, 3]... and then nest one[2, 1],[2, 2],[2, 3]...Additional information
Most simple way to merge 2 arrays into one multi dimensional is:
The reason this does not work
Because
evenNumbersandoddNumbersare not initialized at the moment of use. If you would declare those inVAR CONSTANTit would probably work but then you would not be able to change content of those arrays in program.