Dynamically created arrays

Hi Folks
Battling with a 2D array creation. I want to store some user detail against a device mac as the Key (In my example below 1, 2 & 3). If I manually create the structure I can change each field individually. If I create them dynamically in a loop with the “same” commands, changing one field updates all 3 fields on that level.

Any suggestions ?

:local array ({}) ;
:set ( array → “1” ) ({}) ;
:set ( array → “1” → “test” ) false ;
:set ( array → “2” ) ({}) ;
:set ( array → “2” → “test” ) false ;
:set ( array → “3” ) ({}) ;
:set ( array → “3” → “test” ) false ;

:log info $array ;
:set (array → “2” → “test” ) true ;
:log info $array ;

Result :
1=test=false;2=test=false;3=test=false
1=test=false;2=test=true;3=test=false

:local array2 ({}) ;
:local list {“1”; “2”; “3”} ;
:foreach a in=$list do={
:set ( $array2 → $a ) ({}) ;
:set ( $array2 → $a → “test” ) false ;
} ;

:log info $array2 ;
:set (array2 → “2” → “test” ) true ;
:log info $array2 ;

Result :
1=test=false;2=test=false;3=test=false
1=test=true;2=test=true;3=test=true

To use Key=Value array, try this:
Use {} around code so it can run directly from terminal, and change log to put to get info on screen.

{
:local array ({})
:local list {"1"; "2"; "3"}
:foreach a in=$list do={
	:set ( $array -> "$a" ) ({})
	:set ( $array -> "$a" ) false
}

:put $array
:set ($array -> "2") true
:put $array 
}

Result:

1=false;2=false;3=false
1=false;2=true;3=false

Some script info:
Use code tags when posting code in the forum. Better to read and tabs in front will be seen.</>
You do not need semicolon after all lines, only between commands on same line ;
From the Wiki, MT stats that $ should be used when set a variable. I do see it works without, so not 100% sure whats the best way: https://wiki.mikrotik.com/wiki/Manual:Scripting#Operations_with_Arrays

Thanks Jotne
Making those changes causes the key to become lost. I’d ideally like to retain the key functionality.
My ultimate goal is a dynamic array like this :
maclist={A1:B1:C1:D1:E1:F1={ firstseen=April202020; lastseen=April252020; throttled=false }; A2:B2:C2:D2:E2:F2={firstseen=April252020; lastseen=April262020; throttled=true }} etc
Creating the array one mac at a time works from the DHCP script, as well updating it.
Now I’d like to create the global array from a script using an address list as the source. The dates will be updated from the DHCP script and the throttle status from a scheduled script.
The array commands and the looping dont like each other. Thank you for the constructive comments on scripting. Rgds Puffer

Create multiple array with mac as ID for all. One array has first seen, one array has last seen etc.

Some like this

maclist {A1:B1:C1:D1:E1:F1; A2:B2:C2:D2:E2:F2} 
maclist_firstseen {A1:B1:C1:D1:E1:F1=April202020;A2:B2:C2:D2:E2:F2=April252020}
maclist_lastseen {A1:B1:C1:D1:E1:F1=April252020;A2:B2:C2:D2:E2:F2=April262020}
maclist_throttled {A1:B1:C1:D1:E1:F1=false; A2:B2:C2:D2:E2:F2=true}