I am using PowerShell 2.0. When I make a new variable as an array and then set another variable to be equal to the first one, the second variable "mirrors" the first one. After changing an object in the original array, the exact same change appears in the second array. For instance,
$array0001 = 6, 7, 3, 4, 0
$array0002 = $array0001
$array0001[3] = 55
$array0002
with the output being
6
7
3
55
0
I notice that when you set the second variable to have the same value as the first variable, except this time enclosed within a subexpression operator, modifications to the first array do not affect the second array. For instance,
$array0001 = 6, 7, 3, 4, 0
$array0002 = $($array0001)
$array0001[3] = 55
$array0002
with the output being
6
7
3
4
0
Why does enclosing the value in a subexpression operator change the behavior of the variable? Is there another or better way to avoid making array variables that "mirror" each other?
ETA: I have now found that $array0002 = @($array0001)
and $array0002 = &{$array0001}
both accomplish the exact same objective.