Tech Tip: Adding elements into 2D array
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: March 7, 2014
According to the 4D docs, a 2D array can be denoted like: $arr2d{$x}{$y}, where $x is the number of rows, and $y is the number of columns.
- To add an element to the first row second column, do the following: $arr2d{1}{2}:=1.
- To add rows into an 2D array, use the following command: INSERT IN ARRAY($arr2D;$x).
- To add columns into an 2D array, use the following command: APPEND TO ARRAY($arr2d{$x};$y), where $x is the row you want to add a column to.
Below is an example of how to insert values into a 2D array.
C_LONGINT($x;$y) ARRAY LONGINT($arr2D;0;0) $x:=1 $y:=1 For ($x;1;10) INSERT IN ARRAY($arr2D;$x) For ($y;1;5) Append To ARRAY($arr2D{$x};$y) End For End for |
The end result is a 2D array with 10 rows and 5 columns.