An array is a neat little data structure that allows you to
store more than one piece of information in a single variable. Take a look at the examples below.
$VariableName
|
10
|
In this example, we have a standard variable. It contains only one value.
PS C:\> $VariableName
10
An array is a bit different.
It stores each value in a unique index number.
$Array1
|
0
|
Apple
|
1
|
Pear
|
2
|
Plum
|
PS C:\> $array1
Apple
Pear
Plum
PS C:\> $array1[1]
Pear
A multidimensional array is like a grid (2 dimensional) or a
cube (3 dimensional). You can add more
dimensions but those beyond 3 are hard to conceptualize.
$Array2
|
|
0
|
1
|
2
|
0
|
Dog
|
Alpha
|
100
|
1
|
Cat
|
Bravo
|
200
|
2
|
Bird
|
Charlie
|
300
|
Take a look at this code:
$Data1 = "Dog", "Alpha", "100"
$Data2 = "Cat","Bravo","200"
$Data3 = "Bird","Charlie","300"
$Array3 = @($Data1,$Data2,$Data3)
$Array3[1][2]
This will set up the array that is visualized above. The first index number is how many cells down
to go. The second is how many cells to
the right to go. Remember, both start at
zero.
$Array3[1][2]
200
We essential created 3 arrays; $Data1, $Data2, and
$Data3. We then created an array of arrays called
$Array3.
Comments