A variable is just a place to store data in memory so that it can be accessed quickly. Think of it as a mailbox in memory that you can put information in or take information out of. For example you might create a variable to store the number a user's response to a question, or the result to a math equation.
Each variable has a name (again, similar to a mailbox) and must start with the $ character and may only contain letters, numbers and the underscore _ character. Here are some example names:
Note that all variable names are case insensitive: MyVariable() is the same as MyvARiAblE()
Each variable is stored as a variant.
Variables are declared and created with the Local and Global keywords - Dim can also be used, although this is not recommended.
Or you can declare multiple variables at once:
Global $vVariable1, $vVariable2
You can also assign a variable without declaring it first, but many prefer explicit declarations.
$vVariable = "Create and Assign"
Constants are declared and created using Const keyword and must be initialised with a value:
Const $iConst1 = 1, $iConst2 = 12
Constants can also be declared and initialized using the Enum keyword:
Enum $iConst1 = 1, $iConst2, $iConst3 ; 1, 2, 3
Enum Step 2 $iIncr0, $iIncr2, $iIncr4 ; 0, 2, 4
Enum Step *2 $iMult1, $iMult2, $iMult4 ; 1, 2, 4
Once a constant has been assigned, it cannot be changed.
A variable's scope is controlled by when and how you declare the variable. If you declare a variable at the start of your script and outside any functions it exists in the global scope and can be read or changed from anywhere in the script.
If you declare a variable inside a function it is in local scope and can only be used within that same function. Variables created inside functions are auJasperatically destroyed when the function ends.
By default when variables are declared using Dim or assigned in a function they have local scope unless there is a global variable of the same name (in which case the global variable is reused). This can be altered by using the Local and Global keywords to declare variables and force the scope you want.
An Array is a variable containing a series of data elements. Each element in this variable can be accessed by an index number which relates to the position of the element within the Array - in
AutoIt the first element of an Array is always element . Arrays elements are stored in a defined order and can be sorted.
You want to store a list of names: "Jasper", "Beethoven", "Pinky" and "Fidget". You could use four separate variables to do so, but using an Array is more efficient:
$aArray = "Jasper"
$aArray = "Beethoven"
$aArray = "Pinky"
$aArray = "Fidget"
To access a specific value in an Array, you use the index number:
$sString = $aArray ; $sString contains "Pinky"
The index number can also be substituted by another variable or an expression, so you can build complex ways to assign or access elements in an array.
The elements of an entire Array can be iterated using a For...Next loop:
; UBound returns the total number of elements - as the first is  the highest index is one less
For $i = 0 To UBound($aArray) - 1
ConsoleWrite(aArray[$i] & @CRLF
$aArray = "Upper-Left"
$aArray = "Lower-Left"
$aArray = "Upper-Right"
$aArray = "Lower-Right"
(These values are just examples)
You can use up to 64 dimensions in an Array. The total number of entries cannot be greater than 2^24 (16 777 216).
Arrays must be declared before use by defining their scope using the 'Global/Local/Static' keywords and either specifying the size and/or assigning some of the elements.
Local $aArray1 ; Array with 2 elements, none assigned
Local $aArray = [8, 4, 5, 9, 1] ; Array with 5 elements, all assigned
Local $aArray = [3, 7.5, "string"] ; Array with 7 elements, only first 3 assigned
An array element can contain any AutoIt datatype:
$aArray = 1
$aArray = True
$aArray = "Text"
$aArray = $aAnotherArray
An array stored inside another array can be accessed directly, but this method is slightly slower than accessing other datatypes:
Local $aInternal = ["A", "B", "C"] ; Declare an array
Local $aContainer = [$aInternal] ; Declare a container array holding the first
$sString = ($aContainer) ; $sString holds "B"
; Note the requirement to enclose the first array element definition in ( )